3

为什么这是不可能的?

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

那么为什么这在从to的关联上是groupProperty不可能的呢?@manyToOneCriteria1ClassCriteria2Class

4

1 回答 1

2

自己解决了:

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

crit1.list();
于 2010-07-22T07:21:48.570 回答