Select Distinct column and Another Column - Oracle Hibernate

752 views Asked by At

I need to select distinct id and also need another column

MyClass  class1 = new MyClass();    
Criteria criteria = new Criteria(MyClass.class);
    ProjectionList projList = Projections.projectionList();
            projList.add(Projections.property("col1"));
            projList.add(Projections.property("col2"));
            criteria.setProjection(Projections.distinct(projList));
class1 = criteria.list();

What will be the return type of criteria.list()? If i try to assign it to MyClass.class I get ClassCast Exception. Please assist. How will I get both my columns?

1

There are 1 answers

0
sp00m On

The result of criteria.list() must be a List<Object[]>, so:

List<Object[]> result = criteria.list();
for (Object[] row : result) {
    Object col1 = row[0];
    Object col2 = row[1];
}