From 2f59edbffc40247ac7a83408eea223a68d717d51 Mon Sep 17 00:00:00 2001 From: "nathan.xu" Date: Thu, 3 Oct 2024 21:12:29 -0400 Subject: [PATCH] HHH-18588 improve page computing --- documentation/src/main/asciidoc/introduction/Interacting.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/introduction/Interacting.adoc b/documentation/src/main/asciidoc/introduction/Interacting.adoc index fc0c693f1e..2252626228 100644 --- a/documentation/src/main/asciidoc/introduction/Interacting.adoc +++ b/documentation/src/main/asciidoc/introduction/Interacting.adoc @@ -997,7 +997,8 @@ The `getResultCount()` method is useful for displaying the number of pages of re SelectionQuery query = session.createSelectionQuery("from Book where title like ?1 order by title", Book.class) .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 books = query.setMaxResults(MAX_RESULTS).getResultList(); ----