假设如下:
public class Enterprise
{
private int id;
private String name;
}
public class Site
{
private int id;
private String name;
private Enterprise enterprise; //@ManyToOne relation
}
public class Area
{
private int id;
private String name;
private Site site; //@ManyToOne relation
}
我想按企业使用休眠标准分组结果执行查询。
Criteria criteria = session.createCriteria(Area.class);
criteria.setProjection(Projections.projectionList()
.add(Property.forName("id").as("id"))
.add(Property.forName("name").as("name"))
.add(Projections.groupProperty("site.enterprise")))
.setResultTransformer(Transformers.aliasToBean(Area.class));
/*
* more conditions
*/
List<Area> areas = criteria.list();
执行此休眠时返回异常:org.hibernate.QueryException:无法解析属性:site.enterprise ...
有没有一些优雅的方法来做到这一点。先感谢您。