title: Hibernate: Using entity with composite key
body: <p>I have a table with composite primary key:</p>
  
  <p>Taking example from tables from other question in SO</p>
  
  <p>the composite primary key class:</p>
  
  <pre><code>@Embeddable 
  public class TimePK implements Serializable {     
  protected Integer levelStation;     
  protected Integer confPathID;  
  protected Integer col1;
  protected Integer col2;    
  
  public TimePK() {}      
  
  public TimePK(Integer levelStation, Integer confPathID, Integer col1, Integer col2) {         
  this.levelStation = levelStation;         
  this.confPathID = confPathID; 
  this.col1 = col1;
  this.col2 = col2; 
  
  }     
  
  // equals, hashCode 
  }
  </code></pre>
  
  <p>and the entity:</p>
  
  <pre><code>@Entity 
  class Time implements Serializable {     
  
  @EmbeddedId     
  private TimePK timePK;      
  
  private String src;     
  private String dst;     
  private Integer distance;     
  private Integer price;      
  //... 
  } 
  </code></pre>
  
  <p>There will be two entries in persistent.xml as:</p>
  
  <p>com.somepackage.Time
  com.somepackage.TimePK</p>
  
  <p>Question:</p>
  
  <p>How to use above classes in a query??
  e.g. Find confPathId, col2 where levelstation is 10 and col1 is 20  -- what will be hibernate query for this requirement ?</p>
  
  <p>Using "from TimePK T" in the query is giving "TimePK is not mapped" error!!</p>