title: hibernate Mapping One to many relation ship between primary key and composite key
body: <p>I am struggling with a hibernate mapping problem of mapping One to many relation ship between Primary key of Order Table and composite key of Product Cart with some extra columns</p>
  
  <pre><code>public class OrderDetails implements Serializable {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  @Id
  @Column(name="ORDERID")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Integer orderId;
  
  @Column(name="ORDER_DATE")
  private Date orderDate= new Date();
  //other fields and getter setter
  .....
  .....
  </code></pre>
  
  <p>Product Cart table has a composite key CART ID and PRODUCT ID</p>
  
  <pre><code>@Entity
  @Table(name="PRODUCT_CART")
  @AssociationOverrides({
      @AssociationOverride(name="pk.shopCart", joinColumns=@JoinColumn(name="CARTID")),
      @AssociationOverride(name="pk.product", joinColumns=@JoinColumn(name="PRODUCTID"))
  })
  public class ProductCart implements Serializable {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  @EmbeddedId
  private ProductCartId pk = new ProductCartId();
  
  @Column(name="QUANTITY")
  private Integer selectedQuantity=1;
  
  @Column(name="TOTAL")
  private double total=0.0;
  //other fields and getter setter
  .....
  .....
  </code></pre>
  
  <p>I tried following but not working </p>
  
  <pre><code>@Entity
  @Table(name="PRODUCTCART_ORDERDETAILS")
  @AssociationOverrides({
  @AssociationOverride(name="pcoPK.orderDetails",joinColumns=@JoinColumn(name="ORDERID"))    ,
  @AssociationOverride(name="pcoPK.pk", joinColumns=       
      {@JoinColumn(name="pk.shopCart",referencedColumnName="CARTID"),
      @JoinColumn(name="pk.product",referencedColumnName="PRODUCTID") }) })
  
  public class ProductCartOrder implements Serializable {
  
  /**
   * 
   */
  private static final long serialVersionUID = -2348674131019001487L;
  
  @EmbeddedId
  private ProductCartOrderId pcoPK = new ProductCartOrderId();
  
  @Column(name="QUANTITY")
  private Integer quantity;
  
  @Column(name="PRICE")
  private double price;
  
  @Transient
  public OrderDetails getOrderDetails(){
      return getPcoPK().getOrderDetails();
  }
  public void setOrderDetails(OrderDetails orderDetails){
      getPcoPK().setOrderDetails(orderDetails);
  }
  
  @Transient
  public ProductCartId getProductCartId(){
      return getPcoPK().getPk();
  }
  public void setProductCartId(ProductCartId pk){
  getPcoPK().setPk(pk);
  }
  </code></pre>
  
  <p>Can someone please help me to implement this? Below is the error message</p>
  
  <p>Caused by: org.hibernate.AnnotationException: Illegal attempt to define a @JoinColumn with a mappedBy association: pcoPK.pk
      at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumn(Ejb3JoinColumn.java:152)
      at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumns(Ejb3JoinColumn.java:127)
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1212)
      at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1841)
      at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1878)</p>