wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes I can set the max results on a query, but can I find what the total would have been without (Paging) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "I can set the max results on a query, but can I find what the total would have been without (Paging)" Watch "I can set the max results on a query, but can I find what the total would have been without (Paging)" New topic
Author

I can set the max results on a query, but can I find what the total would have been without (Paging)

Theodore David Williams
Ranch Hand

Joined: Dec 21, 2009
Posts: 102
I am executing a query and on that query I am setting the max results I want back from the data base. How ever I still need to know what the total number of results would have been if I did not limit the query.



I think I can setup a criteria, but then I would have to but in the same info as in my query object, do I really need to create a criteria object and query the DB again to the total?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

As a general database question, the main point of telling the database to just give you the top 50 results is so that it doesn't have to go through all 12,397 results. And therefore it would be completely unreasonable to expect it to produce the number 12,397 from that top-50 query.

Does that answer your question?

Also, the usual way to find out the size of a query is to use a "Select count(*) from ..." type of query. That also frees the database from having to return all 12,397 rows across the network just so that something can count the rows. But sorry, I don't know how you do that with an entity manager.
 
Don't get me started about those stupid light bulbs.
 
subject: I can set the max results on a query, but can I find what the total would have been without (Paging)
 
Similar Threads
feedback on this proposed design
LazyInitializationException illegal access to loading collection
Hibernate query with criteria as an object
Hibernate HQL: Query to Criteria
Hibernate Newbie, help on queries that do some grouping