views:

2302

answers:

3

how can we get distinct result by using criteria in hibernate.

+4  A: 
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

See also https://forum.hibernate.org/viewtopic.php?t=941669

bwalliser
+1  A: 

A more flexible solution may be:

criteria.setProjection(Projections.dinstinct(Projections.property("property")));
waxwing
A: 

depends on your query/criteria. if you provide a unique id you can call criteria.uniqueResult() otherwise you call criteria.setMaxResults(1) and call criteria.uniqueResult()

Salandur