How to add Distinct in Hibernate Criteria

Use Projections.distinct.

Criteria crit = session.createCriteria(Test.class).setProjection(
    Projections.distinct(Projections.projectionList()
    .add(Projections.property("type"), "type") )
.setResultTransformer(Transformers.aliasToBean(YourBean.class)); 

List lst = crit.list();

where YourBean.class has a property “type”. The returned list will be List<YourBean>.

Leave a Comment