title: Hibernate composite key which are foreigen key to another table
body: <p>I have two table Part and SubPart. Part table has general fields like id, name, desc etc. The SubPart table has part_id, sub_part_id as composite key. Both of these columns are referring to Part table and has a one to many mapping for each of them, like for each part_id in the Part table there can be multiple entries in SubPart table for both the columns. I'm having problem defining the composite key for the SubPart table. I tried the Embedded tag but its not working. How can I address this problem. Thanks a lot.</p>
  
  <p>Part table like this.</p>
  
  <pre><code>@Entity
  @Table(name="Part")
  public class Part {
  
      @Id
      @GeneratedValue
      @Column(name="Part_Id")
      private int id;
      @Column(name="Part_Number")
      private String partNumber;
      @Column(name="Part_Name")
      private String partName;
  }
  </code></pre>
  
  <p>Sub Part Table</p>
  
  <pre><code>@Entity
  @Table(name="SubPart")
  public class SubPart {
      // part and subPart combination is the compound key here.
      @ManyToOne
      @JoinColumn(name="Part_Id")
      private Part part;
  
      @ManyToOne
      @JoinColumn(name="Sub_Part_Id")
      private Part subPart;
  
      @Column(name="Quantity")
      private Integer quantity;
  }
  </code></pre>