{"record":{"id":"bb8fc5b7718baa48","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-call-page-page-bb8fc5","errorCode":null,"errorMessage":"Cannot call a page related method, call page(Page) or page(int, int) to initiate pagination first","messagePattern":"Cannot call a page related method, call page\\(Page\\) or page\\(int, int\\) to initiate pagination first","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java","lineNumber":200,"sourceCode":"\n    public Uni<Integer> pageCount() {\n        checkPagination();\n        return count().map(count -> {\n            if (count == 0)\n                return 1; // a single page of zero results\n            return (int) Math.ceil((double) count / (double) page.size);\n        });\n    }\n\n    public Page page() {\n        checkPagination();\n        return page;\n    }\n\n    private void checkPagination() {\n        // FIXME: turn into Uni\n        if (page == null) {\n            throw new UnsupportedOperationException(\"Cannot call a page related method, \" +\n                    \"call page(Page) or page(int, int) to initiate pagination first\");\n        }\n        if (range != null) {\n            throw new UnsupportedOperationException(\"Cannot call a page related method in a ranged query, \" +\n                    \"call page(Page) or page(int, int) to initiate pagination first\");\n        }\n    }\n\n    public Range range() {\n        checkRange();\n        return range;\n    }\n\n    public void range(int startIndex, int lastIndex) {\n        this.range = Range.of(startIndex, lastIndex);\n        // reset the page to its default to be able to switch from page to range\n        this.page = null;\n    }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java#L182-L218","documentation":"Page navigation methods on PanacheQuery require that pagination was initialized via page(Page)/page(int,int). checkPagination throws UnsupportedOperationException if page is null, and a second variant if a range was set instead (range and paging are mutually exclusive).","triggerScenarios":"Calling nextPage(), previousPage(), firstPage(), lastPage(), hasNextPage(), or hasPreviousPage() on a PanacheQuery that never had page(...) called, or on a query configured with range(from,to).","commonSituations":"Conditional paging code where page() is only called sometimes; calling hasNextPage() right after find() before page(); mixing range() and page() in shared query-builder code.","solutions":["Call query.page(Page.of(index, size)) (or page(index, size)) before any page-navigation method","Do not mix range() with page methods — pick one paging style","Guard the navigation calls behind a check that paging was initialized"],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"active\");\nboolean more = q.hasNextPage();\n// after\nPanacheQuery<Person> q = Person.find(\"active\").page(Page.of(0, 20));\nboolean more = q.hasNextPage();","handlingStrategy":"validation","validationCode":"PanacheQuery<Person> q = Person.find(\"active\");\nif (!isPaged(q)) q.page(Page.of(0, 20));","typeGuard":"static boolean isPaged(PanacheQuery<?> q) {\n    try { q.pageCount(); return true; }\n    catch (UnsupportedOperationException e) { return false; }\n}","tryCatchPattern":"try {\n    return q.nextPage();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"initiate pagination first\")) {\n        return q.page(Page.of(0, 20)).nextPage();\n    }\n    throw e;\n}","preventionTips":["Always call page(Page) or page(int,int) immediately after find() when using page APIs","Never mix range() and page() on the same query","Encapsulate query construction so paging is always initialized before navigation"],"tags":["quarkus","panache","hibernate-reactive","pagination","unsupported-operation"],"backgroundTag":"pagination-not-initialized","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}