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).
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论