• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Finding the total result size using Hibernate Query and pagination

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I'm using Hibernate/HQL/named queries to retrieve data from a database. In particular I use pagination (i.e. I control the number of results that are returned on any one query) so as not to pull thousands of rows from the database.

Here's the java code I have right now:



What I'd like to be able to do, however, is find out how many total results this query will return independent of the pagination (so I can display something like "Results 31 through 40 of 123" to the end user). I've looked at the Hibernate Query API but don't see anything help. Any ideas?

Thanks,
Dave
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello David,

I been there before and what i did was kinda like a double query, one for the result and the other one for the count of the unpaged results. Hibernate do have a ScrollableResult that could help you a little with this.

This it's a reality that many of us encounter time to time when working with db, because of the paging and all that stuff, but there it's a pattern to solve this. Here explains about the Pagination pattern with diagrams and stuff.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic