Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hate to tell you this, but you have a bi-directional relationship there. The Person has a reference to the Heart and Liver and each of those have a reference back to the Person. The annotations that you have set up on the Id properties of your Heart and Liver are specifically saying that they get the value of their Id property by delegating to their Person property. In the examples that you've shown that don't work, you haven't set the Person property on those guys yet and so, they obviously cannot obtain their Id value.</p> <p>You can either set this relationship up as a true unidirectional OneToOne, which is documented in the Hibernate annotations documentation:</p> <pre><code>@Entity public class Body { @Id public Long getId() { return id; } @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn public Heart getHeart() { return heart; } ... } @Entity public class Heart { @Id public Long getId() { ...} } </code></pre> <p>or you can change our entity objects slightly to streamline hooking up both sides of the relationship such as:</p> <pre><code>@Entity public class Person { public long personId; private String name; public Heart heart; public Liver liver; // other fields @Id @GeneratedValue public long getPersonId() {return personId;} @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn public Heart getHeart() {return heart;} public void setHeart(Heart heart){ this.heart = heart; this.heart.setPerson(this); } @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn public Liver getLiver() {return liver;} public void setLiver(Liver liver){ this.liver = liver; this.liver.setPerson(this); } // other getters and setters and constructors } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload