I have a chunk of code that gets handed an arbitrary org.hibernate.Query object. This query is not a 'count' query. How do I get the number of items that would be returned fr开发者_Python百科om that query without pulling apart the sql string from the query?
I ran across the org.hibernate.Criteria object in my research for this problem, which does have the setProjection(Projections.rowCount())
method. But I was unable to find a way to convert the Query object into a Criteria object or find a similar method for the Query object.
Thanks in advance.
You could use Query.scroll()
, got to the last position using ScrollableResults.last()
, and call getRowNumber()
.
Note though that this will give you the number of SQL rows, and not necessarily the number of entities returned by the query (if there is a join fetch on a collection, for example).
精彩评论