title: How to define @OneToMany in parent entity when child has composite PK?
body: <p>My <code>Parent</code> class has two child classes:  <code>Child</code> and <code>ParentHobby</code>.  The Child class has a singular PK and the <code>@OneToMany</code> mapping on it works.  The problem is that I don't know how to map it on the ParentHobby class, which has a composite PK.</p>
  
  <p><strong>Parent:</strong></p>
  
  <pre><code>//this works
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", fetch = FetchType.EAGER)
  private List&lt;Child&gt; childList;
  
  //this DOES NOT work
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", fetch = FetchType.EAGER)
  private List&lt;ParentHobby&gt; hobbyList;
  </code></pre>
  
  <p><strong>Child:</strong></p>
  
  <pre><code>@Entity
  @Table(name="CHILD")
  public class Child {
  
  
      @Id
      @SequenceGenerator(name="CHILD_SEQ", sequenceName="CHILD_DB_SEQ", allocationSize = 1)
      @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CHILD_SEQ")
      @Column(name="CHILD_ID")
      private long childID;
  
      @JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID", insertable = true, updatable = true)
      @ManyToOne(optional = true)
      private Parent parent;
  </code></pre>
  
  <p><strong>ParentHobby:</strong></p>
  
  <p>@Entity
  @Table(name="PARENT_HOBBY")
  public class ParentHobby {</p>
  
  <pre><code>@EmbeddedId
  private ParentHobbyPK id;
  </code></pre>
  
  <p><strong>ParentHobbyPK:</strong></p>
  
  <pre><code>@Embeddable
  public class ParentHobbyPK {
  
      @JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID", insertable = true, updatable = true)
      @ManyToOne(optional = true)
      private Parent parent;
  
      @Column(name="HOBBY_ID")
      private String hobbyID;
  </code></pre>
  
  <p>The exception I get at compile time is:</p>
  
  <pre><code>mappedBy reference an unknown target entity property: ParentHobby.parent in Parent.hobbyList
  </code></pre>
  
  <p><strong>How can I define a @OneToMany relationship in a parent entity when the child has a composite primary key?</strong></p>
  
  <p><sub>SIMILAR:</p>
  
  <p><a href="https://stackoverflow.com/questions/9162755/onetomany-relationship-with-composite-key">@OneToMany relationship with Composite key</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30669034/hibernate-entity-mapping-when-foreign-key-is-part-of-the-composite-primary-key">Hibernate Entity mapping when Foreign key is part of the composite primary key?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7569702/jpa-composite-key-onetomany">JPA composite key @OneToMany</a></sub></p>