当 DetachedCrieria 有投影时,如何获取 DetachedCriteria 结果集的行数?对于 HQL:
select count(*) from (select name, sum(grade) from score group by name)。
对于hibernate,如何实现Subqueries.rowCount(DetachedCriteria dc)?谢谢。
当 DetachedCrieria 有投影时,如何获取 DetachedCriteria 结果集的行数?对于 HQL:
select count(*) from (select name, sum(grade) from score group by name)。
对于hibernate,如何实现Subqueries.rowCount(DetachedCriteria dc)?谢谢。
如果你想要的只是计数,为什么不直接执行
select count(name) from score group by name
我有同样的问题......我想出了以下解决方案并且它有效:
myCriteria.setProjection(Projections.sqlProjection("count(*) as count from ( select distinct id , {alias}.enteredDate ", new String[] { "count" }, new Type[] { StandardBasicTypes.LONG }));
// this is needed to close the parentheses opened in the Projection
myCriteria.add(Restrictions.sqlRestriction(" 1=1)"));