有没有办法为以下sql编写hibernate标准:
select count(*) from tableA group by columnA, columnB, columnC;
基本上,我想从默认添加的select子句中排除group属性。
示例:
session.createCriteria(TableA.class)
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("columnA"))
.add(Projections.groupProperty("columnB"))
.add(Projections.groupProperty("columnC"))
.add(Projections.rowCount()));
将导致
select columnA, columnB, columnC, count(*) from tableA group by columnA, columnB, columnC;
感谢。
答案 0 :(得分:1)
参考下面的代码::
Integer totalResult = ((Number)criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
你也可以尝试这个:::
int count = ((Long)getSession().createQuery("select count(*) from table_a group by column_a").uniqueResult()).intValue();