• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate: Row count for pagination

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Pagination purpose, it is possible to return the row counts and the query result in the same query?

If I have a User table, and my code is like that:


How can I make the same query return the row count of this query?

Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I have seen some people run two queries. The first to get the entire count like select count(*) from Object o where...

Then they do their second query as pagination.

Now I recommend doing the first query once up front, so that on subsequent pages don't rerun that first query.

Mark
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!