为什么这不可能?
Criteria crit1 = sess.createCriteria(Criteria1Class.class);
Criteria crit2 = crit1.createCriteria("criteria2Class");
crit2.setProjection(Projections.groupProperty("criteria2Property"));
List<String> l2 = crit2.list();
如果我使用这种结构,我会收到错误:
could not resolve property: criteria2Property of: com.foo.bar.models.Criteria1Class
offcourse criteria2Property在Criteria1Class
中不存在,因为它存在于Criteria2Class
那么为什么groupProperty
@manyToOne
关联从Criteria1Class
到Criteria2Class
无法实现{{1}}?
答案 0 :(得分:2)
自己解决了:
Criteria crit1 = sess.createCriteria(Criteria1Class.class)
.createAlias("criteria2Class","criteria2ClassAlias")
.setProjection(Projections.groupProperty("criteria2ClassAlias.criteria2Property"));
crit1.list();