This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

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

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 0.51 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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();
clone this paste RAW Paste Data