1

当 DetachedCrieria 有投影时,如何获取 DetachedCriteria 结果集的行数?对于 HQL:

select count(*) from (select name, sum(grade) from score group by name)。

对于hibernate,如何实现Subqueries.rowCount(DetachedCriteria dc)?谢谢。

4

2 回答 2

0

如果你想要的只是计数,为什么不直接执行

select count(name) from score group by name
于 2013-02-21T16:19:49.420 回答
0

我有同样的问题......我想出了以下解决方案并且它有效:

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)"));
于 2013-03-06T00:43:38.417 回答