views:

87

answers:

1

why is this not possible?

Criteria crit1 =  sess.createCriteria(Criteria1Class.class);
Criteria crit2 = crit1.createCriteria("criteria2Class");

crit2.setProjection(Projections.groupProperty("criteria2Property"));
List<String> l2 = crit2.list();

If I use this construction I get the error:

could not resolve property: criteria2Property of: com.foo.bar.models.Criteria1Class

offcourse criteria2Property doesn't exist in Criteria1Class because it exist in Criteria2Class

So why is this groupProperty not possible on the @manyToOne associations from Criteria1Class to Criteria2Class?

+1  A: 

Solved it myself:

Criteria crit1 =  sess.createCriteria(Criteria1Class.class)
                  .createAlias("criteria2Class","criteria2ClassAlias")
                  .setProjection(Projections.groupProperty("criteria2ClassAlias.criteria2Property"));

crit1.list();
michel