Reputation: 314
can anyone tell me how to use hibernate criteria with Distinct and order by. i've been looking for a solution but can't seem to find one
thanks.
Upvotes: 3
Views: 2350
Reputation: 751
This is the code is Used to retrieve the data of a city.
List<City> entityList = (List<City>)session.createCriteria(className)
.setProjection(Projections.projectionList()
.add(Projections.distinct(Projections.property("state"))))
.addOrder(Order.asc("state")) .add(criterion).list();
Upvotes: 0
Reputation: 2097
Have you tried the following? criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Reference: http://www.roseindia.net/hibernate/examples/criteria/hibernate-distinct-criteria.html
Upvotes: 1