title: sharing foreign key Hibernate
body: <p>I am trying to code this model using JPA + Hibernate 
  <a href="https://i.stack.imgur.com/EUCWS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EUCWS.jpg" alt="enter image description here"></a></p>
  
  <p>here is my code for entity level one</p>
  
  <p><strong>Entity level one</strong></p>
  
  <pre><code>@Entity
  public class LevelOne {
  @EmbeddedId
  LevelOnePK levelOnePK;
  
  @OneToOne(mappedBy = "levelOne")
  private LevelTwo levelTwo;
  
  private String valueCol;
  
  //getters setters omitted 
  }
  </code></pre>
  
  <p><strong>level one Pk</strong></p>
  
  <pre><code>@Embeddable
  public class LevelOnePK implements Serializable {
  private int idOne;
  private int idTwo;
  private int idThree;
  
  //getters setters omitted 
  }
  </code></pre>
  
  <p><strong>Entity Level two</strong></p>
  
  <pre><code>@Entity
  public class LevelTwo {
  
  @Id
  private int LondId;
  
  @OneToOne
  @JoinColumn(name = "lone_id_one")
  @JoinColumn(name = "lone_id_two")
  @JoinColumn(name = "lone_id_three")
  private LevelOne levelOne;
  
  @OneToOne(mappedBy = "levelTwo")
  private LevelThree levelThree;
  
  //getters setters omitted
  }
  </code></pre>
  
  <p><strong>Entity Level three</strong></p>
  
  <pre><code>@Entity
  public class LevelThree {
  
  @Id
  private int LondId;
  
  @OneToOne
  @JoinColumn(name="l_one", referencedColumnName="lone_id_one", insertable=false, updatable=false)
  @JoinColumn(name="l_two", referencedColumnName="lone_id_two", insertable=false, updatable=false)
  @JoinColumn(name="l_three", referencedColumnName="lone_id_three", insertable=false, updatable=false)
  private LevelTwo levelTwo;
  
  private String valueCol;
  //getters setters omitted
  }
  </code></pre>
  
  <p><strong>What this code is doing</strong></p>
  
  <p>this code is successfully mapping PK of Level one entity to Level two entity as foreign key. </p>
  
  <p><strong>Where I am having problem</strong>
  I am unable to map composite foreign key of Level two entity into Level three entity and getting this error</p>
  
  <pre><code>Caused by: org.hibernate.AnnotationException: referencedColumnNames(lone_id_one, lone_id_two, lone_id_three) of com.example.testQuestions.LevelThree.LevelThree.levelTwo referencing com.example.testQuestions.LevelTwo.LevelTwo not mapped to a single property
  </code></pre>
  
  <p>where I am doing wrong?</p>