HHH-18588 improve page computing

This commit is contained in:
nathan.xu 2024-10-03 21:12:29 -04:00 committed by Gavin King
parent 942474f901
commit 2f59edbffc
1 changed files with 2 additions and 1 deletions

View File

@ -997,7 +997,8 @@ The `getResultCount()` method is useful for displaying the number of pages of re
SelectionQuery<Book> query = SelectionQuery<Book> query =
session.createSelectionQuery("from Book where title like ?1 order by title", Book.class) session.createSelectionQuery("from Book where title like ?1 order by title", Book.class)
.setParameter(1, titlePattern); .setParameter(1, titlePattern);
long pages = (long) Math.ceil(query.getResultCount() * 1.0 / MAX_RESULTS); long results = query.getResultCount();
long pages = results / MAX_RESULTS + (results % MAX_RESULTS == 0 ? 0 : 1);
List<Book> books = query.setMaxResults(MAX_RESULTS).getResultList(); List<Book> books = query.setMaxResults(MAX_RESULTS).getResultList();
---- ----