{"record":{"id":"17b39b65859deecf","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-in-a-ranged-quer-17b39b","errorCode":null,"errorMessage":"Cannot call a page related method in a ranged query, call page(Page) or page(int, int) to initiate pagination first","messagePattern":"Cannot call a page related method in a ranged query, 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":204,"sourceCode":"            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    }\n\n    private void checkRange() {\n        if (range == null) {\n            throw new UnsupportedOperationException(\"Cannot call a range related method, \" +","sourceCodeStart":186,"sourceCodeEnd":222,"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#L186-L222","documentation":"Thrown by CommonAbstractPanacheQueryImpl.checkPagination when a page-related method (nextPage, previousPage, firstPage, lastPage, hasNextPage, hasPreviousPage) is invoked on a Hibernate Reactive Panache query that was never paged, or that was configured with range(int,int) instead of page(). Panache requires pagination to be initialized before page navigation/inspection because the Page state is what those methods operate on. It is an UnsupportedOperationException, i.e. a programming/API-usage error, not a runtime environment failure.","triggerScenarios":"Calling nextPage()/previousPage()/firstPage()/lastPage()/hasNextPage()/hasPreviousPage() on a PanacheQuery created via find()/list()/query() without first calling page(Page) or page(int pageIndex, int pageSize); or after calling range(int,int), which puts the query in ranged mode (checkPagination throws when range != null).","commonSituations":"Developers assume a fresh query has an implicit default page (like JDBC-style offset/limit habits); code refactored from range() to pagination but still calling nextPage(); mixing page() and range() on the same query object.","solutions":["Call page(int pageIndex, int pageSize) or page(Page) on the PanacheQuery before invoking any page-related method.","If you only want a bounded result set, use range(int startIndex, int lastIndex) and drop nextPage/previousPage calls entirely.","Remove range(...) calls if you intend to paginate; a query cannot be both paged and ranged.","Use list()/firstResult()/singleResult() instead if pagination helpers are not actually needed."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18);\nboolean more = q.hasNextPage(); // UnsupportedOperationException\n\n// after\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18).page(0, 20);\nboolean more = q.hasNextPage();","handlingStrategy":"validation","validationCode":"if (query.range() != null) { throw new IllegalStateException(\"Query is ranged; page methods unavailable\"); }\n// or track it: ensure you called .page(p, s) before hasNextPage()/nextPage()/firstPage()/lastPage()","typeGuard":null,"tryCatchPattern":"try { more = query.hasNextPage(); } catch (UnsupportedOperationException e) { query.page(0, defaultSize); more = query.hasNextPage(); }","preventionTips":["Always initialize pagination with .page(int, int) immediately after find()/query() when using page helpers","Never mix .range(...) and .page(...) on the same query object","Prefer range(int,int) for simple limit/offset needs and skip page navigation helpers"],"tags":["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-12T22:17:10.623Z"}