assuming following:
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
}
I would like to do execute query using hibernate criteria grouping result by enterprise.
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();
When executing this hibernate returns exeption: org.hibernate.QueryException : could not resolve property: site.enterprise ...
Is there some elegant way how to do this. Thank you in advance.