hibernate Hibernate Entity Relationships using Annotations Bi-Directional One to One Relationship managed by Foo.class

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

@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.

enter image description here



Got any hibernate Question?