Reputation: 12743
how can we get distinct result by using criteria in hibernate.
Upvotes: 9
Views: 20218
Reputation: 18743
A more flexible solution may be:
criteria.setProjection(Projections.distinct(Projections.property("property")));
Upvotes: 6
Reputation: 6293
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
See also https://forum.hibernate.org/viewtopic.php?t=941669
Upvotes: 13
Reputation: 6453
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()
Upvotes: 1