现在有个关于hibernate多主键的问题,请指教:
一个表Result,有两个主键,分别是customerId,setDate,用Middlegen Hibernate plugin生成一个单独的主键类ResultPK.
下面是从数据库生成的result.hbm.xml文件:
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
>
type="int"
column="degree"
length="3"
/>
type="java.lang.String"
column="prize"
not-null="true"
length="2"
/>
type="int"
column="wage"
not-null="true"
length="5"
/>
type="int"
column="train"
not-null="true"
length="2"
/>
现在我想查询表中所有customerId='0001' and setDate='2003-08-12' 的记录,怎么写HQL语句???,急死我了!
我写的HQL语句:
//首先给主键类赋值
ResultPK resultPK = new ResultPK(); //结算主键表
resultPK.setCustomerId("0001");
resultPK.setSetDate("2003-08-12");
//注:comp_id是Result类中ResultPK的实例
//在Result类中有 public ResultPK getComp_id() {}
// public void setComp_id(ResultPK comp_id) {} 方法。
下面是我写的hql语句:
session.find("select result.comp_id from Result result where result.comp_id = "+resultPK+" ");
但是运行时出现错误:就在session.find(....)那行出错:
net.sf.hibernate.QueryException: path expression ends in a composite value: result0_.comp_id [select result.comp_id from com.persistent.Result result where result.comp_id = com.persistent.ResultPK@11946c2[customerId=0001,setDate=2003-08-12] ]
我不知道这样的语句怎么写?请大家帮帮忙!
先谢了。