The display is incorrect.
The main problem you have here is that mappedBy = "child" refers to the child attribute of the Child class, not the Parent class. There is no child attribute in the child class, and you need to refer to the parentPK attribute in the Child class instead.
I suggest leaving PK / FK out of the entity field names, as this can be a bit confusing.
Below are the updated Parent / Child children. (Ive switched to field access, but that's just my preference)
@Entity public class Child { @Id @Column(name = "childPK") private Long id; @OneToOne @JoinColumn( name = "PARENT_FK", referencedColumnName = "PARENT_PK" ) private Parent parent; @Entity public class Parent { @Id @Column(name = "PARENT_PK") private long id; @OneToOne( cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, --> mappedBy = "parent")
Note that you have defined the OneToOne bidirectional relationship. JPA bidirectional relationships have their own side β the side with the connection information, Child in your case β and the flip side is the side with the mappedBy attribute, the parent in your case. It is a good idea to handle this. This link reviews OneToOne relationships, and there are many others around. https://en.wikibooks.org/wiki/Java_Persistence/OneToOne
source share