Hibernate HQL: Get count of results without actually returning them

后端 未结 2 1579
遇见更好的自我
遇见更好的自我 2020-12-15 20:02

I want to get the count of the results of a dynamically-generated HQL query, without actually getting the list of results. Say that the query I have is something like:

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 20:42

    you can get the count of the query result by using:

    criteria.setProjection(Projections.rowCount());
    count=(Long) criteria.uniqueResult();
    

    hope this helps

提交回复
热议问题