I need to create a query and I need COUNT(*) and HAVING COUNT(*) = x.
I\'m using a work around that uses the CustomProjection
If someone needs to do it in grails it would be like:
projections {
groupProperty("id")
sqlGroupProjection(...)
rowCount()
}
Where sqlGroupProjection is available since 2.2.0
/**
* Adds a sql projection to the criteria
*
* @param sql SQL projecting
* @param groupBy group by clause
* @param columnAliases List of column aliases for the projected values
* @param types List of types for the projected values
*/
protected void sqlGroupProjection(String sql, String groupBy, List columnAliases, List types) {
projectionList.add(Projections.sqlGroupProjection(sql, groupBy, columnAliases.toArray(new String[columnAliases.size()]), types.toArray(new Type[types.size()])));
}
http://grepcode.com/file/repo1.maven.org/maven2/org.grails/grails-hibernate/2.2.0/grails/orm/HibernateCriteriaBuilder.java/#267