1

How can I select all distinct rows in hibernate with all data?

If I use this way only IDs will be selected but I need all rows with their data

session.createCriteria(MyClass.class, "c")
.setProjection(Projections.distinct(Projections.id()))

If I use another approach it will not be performed on sql level but filtered after. That's is not good solution if I need to upload 10 000 rows.

.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
Vitalii
  • 10,091
  • 18
  • 83
  • 151

1 Answers1

2

You can set multiple properties as in Using Hibernate's Criteria and Projections to Select Multiple Distinct Columns

 ProjectionList projList = new ProjectionList();
 projList.add(Projections.property("id.state"));
projList.add(Projections.property("id.uspsCity"))
criteria.setProjection(Projections.distinct(projList));
Community
  • 1
  • 1
Paul John
  • 1,626
  • 1
  • 13
  • 15