1:1 Relation (One to One)
Create a new Car entity and add the following attributes:
registration of type Date
mileage of type Integer
kw of type Integer
price of type Double
Close the Car tab and click Yes in the following dialog to save the Car entity
Create a Logbook entity.
Under Entities in the Project Manager, click Car.java and add the Car entity to the entity editor under Attributes.
In the following dialog, choose the One to One (1:1) option.
Apply the setting Bidirectional.
Click OK.
Click Save.
Result:
Entity Car - The Car entity is enhanced by the logbook attribute of type Logbook.
@OneToOne(mappedBy = "car") public Logbook getLogbook() { return logbook; } public void setLogbook(Logbook logbook) { this.logbook = logbook; }Entity Logbook - The Logbook entity is enhanced by the car attribute of type Car.
@OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "car_id") public Car getCar() { return car; } public void setCar(Car car) { this.car = car; }
Note:
Relation im Code per Annotation - In the code, the relation is defined in both entities with the annotation @OneToOne.
To correctly delete a 1:1 relation, you have to delete the corresponding attributes in both entities.