这个问题是关于使用 HibernateCriteria
进行group by
.
这是我的 SQL:
SELECT s.name, max(p.price), min(p.price)
FROM supplier s, product p
WHERE s.supplier_id = p.supplier_id
GROUP BY s.name
我尝试了以下方法:
Criteria criteria = session.createCriteria(Supplier.class);
Criteria prodCrit = criteria.createCriteria("products");
ProjectionList projList = Projections.projectionList();
projList.add(Projections.max("price"));
projList.add(Projections.min("price"));
projList.add(Projections.groupProperty("name"));
prodCrit.setProjection(projList);
List list = criteria.list();
但我收到以下错误:
Exception in thread "main" org.hibernate.QueryException: could not resolve property: price of: com.gtc.hibernate.query.Supplier