title: How to create hibernate composite key and get values from table
body: <p>I am trying to use hibernate annotations for getting data from a MySQL database table which doesn't have a primary key defined.</p>
  
  <p>However the fact is 2 columns of that table together are unique in the table. How can I achieve the same using hibernate annotation?</p>
  
  <p>This is my code</p>
  
  <pre><code>@Entity
  @Table(name = "coc_order_view")
  public class CoCOrderDetailsTest {
  
  @EmbeddedId
  private MyJoinClassKey key;
  
  @Column(name = "coupon_code")
  private String couponCode;
  
  some other columns and their getters and setters .....
  
  @Embeddable
  public class MyJoinClassKey implements Serializable {
  
  private static final long serialVersionUID = -5L;
  
  @Column(name = "product_id")
  private int productId;
  
  @Column(name = "order_id")
  private int orderId;
  
  gettes and setters....
  </code></pre>
  
  <p>And here is my criteria query</p>
  
  <pre><code>Criteria criteria = getHibernatetemplate().getSession().createCriteria(CoCOrderDetailsTest.class);
  criteria.add(Restrictions.eq("status", "New"));
  ArrayList&lt;CoCOrderDetailsTest&gt; orderDet = (ArrayList&lt;CoCOrderDetailsTest&gt;) getHibernatetemplate().get(criteria);
  </code></pre>
  
  <p>I am unable to get all the values from db. Kindly suggest some solutions.</p>