• 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: 17278
6
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic