I want to count the number of group by rows with the hibernate Criteria API, but I can only count the number of rows aggregated in each group:
ProjectionList projectionList = Projections.projectionList() .add(Projections.groupProperty("color")) .add(Projections.rowCount()); Criteria criteria = session.createCriteria("ProductEntity"); criteria.setProjection(projectionList);
In the code above, the code is:
select p.color, count(*) from product p group by p.color
But I want this query:
select count(*) from (select p.color from product p group by p.color)
I know that this is possible using HQL, but I do not want to use it. So how can I do this using the criteria API?
source share