I'm trying to perform the equivalent of the SQL distinct keyword on my Criteria object, but am having little luck finding an example solution online. Here's what I've found so far as an example (from
http://kickjava.com/src/org/hibernate/t ... t.java.htm), but it doesn't compile.
Code:
s.createCriteria(Enrolment.class)
.setProjection( Projections.distinct( Projections.projectionList().add( Projections.property("studentNumber"), "stNumber" )
Here's what I'm trying to do.
Code:
Criteria criteria = session.createCriteria(MyClass.class);
criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property(Table.FIELD_NAME))));
criteria.addOrder(Order.desc(Table.FIELD_NAME));
criteria.setMaxResults(50);
The IDE complains...
The method distinct(ProjectionList) is undefined for the type ProjectionsI've tried using this methodology as opposed to the projections methodology...
Code:
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
... but what I'm finding is that the distinct keyword is not included in the query. Therefore 50 results are returned but then the dupes are pulled out which leaves me with only 43 (lets say) results. The client is requesting that 50 distinct results are returned.
Does anyone have any experience doing this? Thanks a ton!