Question

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

Was it helpful?

Solution

criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

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

OTHER TIPS

A more flexible solution may be:

criteria.setProjection(Projections.distinct(Projections.property("property")));

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top