Ammad
Ammad

Reputation: 4225

Hibernate Criteria with projection is not picking data

I am using Hibernate criteria and projection to get distinct values as shown below:

Criteria criteria = this.getSession().createCriteria(CmError.class);

ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("router"));
projList.add(Projections.property("slot"));
criteria.setProjection(Projections.distinct(projList));

I am using result Transformer with Projection to get list of distinct values

List<CmError> cm =  criteria.setResultTransformer(Transformers.aliasToBean(CmError.class)).list();

What i am seeing is that all the field values for the list is null while the size of list is correct, meaning number of records i am expecting to return from same distinct SQL query is same as size of the CmError list but data inside list is not populating and returning null when I iterate over the list.

Not sure what i am missing.

Upvotes: 0

Views: 685

Answers (1)

Alex
Alex

Reputation: 11579

Try to change it to:

projList.add(Projections.property("router"), "router");
projList.add(Projections.property("slot"), "slot");

Upvotes: 3

Related Questions