我有複合主鍵的表:休眠:使用實體與複合鍵
以從其他問題表中例如SO
複合主鍵類:
@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
}
和實體:
在persistent.xml作爲@Entity
class Time implements Serializable {
@EmbeddedId
private TimePK timePK;
private String src;
private String dst;
private Integer distance;
private Integer price;
//...
}
將有兩個條目:
com.somepackage.Time com.somepackage.TimePK
問:
如何在查詢中使用上述類? 例如找到confPathId,col2,其中levelstation是10,col1是20 - 對於這個需求,什麼是hibernate查詢?
在查詢中使用「from TimePK T」給出「TimePK未映射」錯誤!
「從時間T開始,其中T.timePK.levelStation = 10和T.timePK.col1 = 20」正確? – Nik
它應該做的工作;你測試過了嗎? –
是的..它的作品..謝謝!測試它! – Nik