Reputation: 3244
I need to create criteria analogous to
select obj, obj.prop.id from Object1 obj group by obj.prop.id
How to do that?
Upvotes: 0
Views: 4698
Reputation: 21000
Example from the reference http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html#querycriteria-projection
List results = session.createCriteria(Cat.class)
.setProjection( Projections.projectionList()
.add( Projections.rowCount() )
.add( Projections.avg("weight") )
.add( Projections.max("weight") )
.add( Projections.groupProperty("color") )
)
.list();
Upvotes: 3