//首先给主键表赋值 ResultPK resultPK = new ResultPK(); //结算主键表 resultPK.setCustomerId("0001");
//注：comp_id是Result类中ResultPK的实例 session.find("select result.comp_id from Result result where result.comp_id = "+resultPK+" ");
运行时出现错误： 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=<null>] ]
the idea is simple; say, you have a composite-id in your Class Result, let assume that the name of it is "id" (and of course, id has two attributes: "customerId" and "setDate"), so we write the following sniplet to retrieve all the records in this table whose customerId='0001'.
select * from Result result where result.id.customerId='0001',
understand? just use double quote marks to enclose it in your HQL and you should be able to get it. cheers