How to write distinct using Hibernate criteria API?
DetachedCriteria crit = DetachedCriteria.forClass(clazz);
Disjunction dis = Restrictions.disjunction(); // OR
dis.add(Restrictions.eq("billType", BillType.RACUN));
dis.add(Restrictions.eq("billType", BillType.STORNO));
crit.add(dis);
crit.setProjection(Projections.distinct(Projections.property("billSubtype")));
Criteria criteria = crit.getExecutableCriteria(getSession());
return crit.list();
select distinct B.BILLSUBTYPE from bill b where (B.BILLTYPE = 'RACUN' or B.BILLTYPE = 'STORNO')
http://www.jairrillo.com/blog/2009/01/29/how-to-use-left-join-in-hibernate-criteria/
No comments:
Post a Comment