hibernate 联合主键

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:56:02
我有个进销存表 里面有四个字段联合作为主键,请问怎么做查询。
还要有条件查询,我发现在另一个不是主键类中,只有一个private 主键类 id
这样怎么做条件查询这个类中的属性啊
跪求答案,但别是网上复制来的,已经查了一下午了,要能解决问题,加倍送分,在线等

Session session=util.HibernateSessionFactory.getSession();
CustomerPK cpk=new CustomerPK();
cpk.setAccountNo("1");
cpk.setAccountName("peter");
Customer cus=(Customer)session.get(Customer.class,cpk );
System.out.println(cus);
util.HibernateSessionFactory.closeSession();

我自己写的一个hibernate得范例,其中AccountNo和setAccountName为联合主键

用联合主键很麻烦啊!
你真的到了万万不得已的情况么?

hql写法

hql = " from table where id.name = ? and id.code= ? and id.** = ?";

不知道楼主看明白了没