title: Hibernate: Primary key made of foreign keys
body: <p>So I have "OrderItem" class. Its primary key its suppose to be made of "productID" and "orderID" (both FK reference from another entities).
  How can I set that up using annotations?</p>
  
  <p>Thanks in advance!!!!</p>
  
  <p><em><strong>Table</em></strong>:
  ordersItems<br>
  <strong><em>Attributes</em></strong>:
  productID (PK-PK)  ------------------> Product<br>
  orderID (PK-PK)    ------------------> Order</p>
  
  <p>Given these entities:</p>
  
  <pre><code>@Entity
  @Table(name="products")
  public class Product {
  
      @Id
      @Column(name="productID")
      private Integer id;
      private String description;
  }
  
  
  @Entity
  @Table(name="orders")
  public class Order{
  
      @Id
      private int orderID;
  
      @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
      @JoinColumn(name="orderID")
      private List&lt;OrderItem&gt; items;
  }
  
  @Entity
  @Table(name="ordersItems")
  public class OrderItem{
  
      @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
      @JoinColumn(name="productID")
      private Product product;
      private int quantity;
      private float price;
  }
  </code></pre>