1:1 Relation (One to One)
-
Create an entity Car and add the following attributes:
-
registration of type date.
-
mileage of type Integer.
-
kw of type Integer.
-
price of the type Double.
-
-
Close the Car tab and click Yes in the following dialog to save the Car entity.
-
Create an entity Logbook.
-
In the Project Manager, click Car.java at Entities and paste the entity Car into the entity editor at Attributes.
-
In the following dialog, select the One to One (1:1) option.
-
Accept the setting Bidirectional.
-
Click OK.
-
Click Save.
Result:
Entity Car - The Car entity is extended by the logbook attribute of type Logbook.
+
@OneToOne(mappedBy = "car")
public Logbook getLogbook()
{
return this.logbook;
}
public void setLogbook(final Logbook logbook)
{
this.logbook = logbook;
}
Entity Logbook - The Logbook entity is extended by the car attribute of type Car.
+
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "car_id")
public Car getCar()
{
return this.car;
}
public void setCar(final Car car)
{
this.car = car;
}