title: jpa hibernate composite foreign key mapping
body: <p>I am having trouble setting up jpa mappings for some entities.  I have a parent entity defined like the following.</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name=&quot;EIF_INSTANCE_HDR&quot;)
  public class InstanceEntity implements Serializable{
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(generator=&quot;eif_inst_gen&quot;)
      @SequenceGenerator(name=&quot;eif_inst_gen&quot;,sequenceName=&quot;EIF_INSTANCE_SEQ&quot;)
      @Column(name = &quot;EAIH_ID&quot;)
      private Long eaihid;
  
      @Column(name = &quot;EAD_ID&quot;)
      private Long eadid;
  
      @OneToMany(targetEntity=InstanceNotifyEntity.class, mappedBy=&quot;instance&quot;,fetch=FetchType.EAGER, cascade = CascadeType.ALL)
      private List&lt;InstanceNotifyEntity&gt; userDetails = new ArrayList&lt;InstanceNotifyEntity&gt;();
  
  }
  </code></pre>
  <p>I then have a child entity w/ a composite key, and a foreign key to the primary key of this table as follows:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name=&quot;EIF_INST_NOTIFIED&quot;)
  public class InstanceNotifyEntity implements Serializable{
  
      private static final long serialVersionUID = 1L;
      
      @Id
      @ManyToOne
      @JoinColumn(name=&quot;EAIH_ID&quot;, referencedColumnName=&quot;EAIH_ID&quot;)
      private InstanceEntity instance;
      
      @Id
      @Column(name=&quot;USER_ID&quot;)
      private Long userId;
  
      @Column(name=&quot;COMMENT_TXT&quot;)
      private String commentText;
  
  }
  </code></pre>
  <p>I know the child entity is incorrect, but I am unsure how to set this up to have a composite PK.  I know I need to setup a PK class, but I am not sure how to do that when one field is a foreign key to the parent class.  And once that is setup how would the parent reference the child entity?</p>
  <p>Any help is appreciated.</p>