我有复合主键的表:休眠:使用实体与复合键
以从其他问题表中例如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