Hibernate
Bi-Directional One to One Relationship managed by Foo.class
@Entity
@Table(name = "FOO")
public class Foo {
private UUID fooId;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "barId")
private Bar bar;
}
@Entity
@Table(name = "BAR")
public class Bar {
private UUID barId;
@OneToOne(mappedBy = "bar")
private Foo foo;
}
Specifies a two-way relationship between one Foo object to one Bar object using a foreign key.
The Foo objects are stored as rows in a table called FOO. The Bar objects are stored as rows in a table called BAR. The
foreign key is stored on the FOO table in a column called barId.
Note that the mappedBy value is the field name on the object, not the column name.