SHARE
TWEET

How to get distinct results in hibernate with joins and row-based limiting (paging)

a guest Feb 28th, 2012 18 Never
  1. criteria.setProjection(Projections.distinct(Projections.property("id")));
  2.        
  3. criteria.setProjection(Projections.distinct(Projections.id()));
  4.        
  5. DetachedCriteria idsOnlyCriteria = DetachedCriteria.forClass(MyClass.class);
  6. //add other joins and query params here
  7. idsOnlyCriteria.setProjection(Projections.distinct(Projections.id()));
  8.  
  9. Criteria criteria = getSession().createCriteria(myClass);
  10. criteria.add(Subqueries.propertyIn("id", idsOnlyCriteria));
  11. criteria.setFirstResult(0).setMaxResults(50);
  12. return criteria.list();
RAW Paste Data
Top