{"record":{"id":"22fe71a2604a6735","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-in-a-ranged-quer","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-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java","lineNumber":291,"sourceCode":"        long count = count();\n        if (count == 0)\n            return 1; // a single page of zero results\n        int pageSize = keyedPage != null ? keyedPage.getPage().getSize() : page.size;\n        return (int) Math.ceil((double) count / (double) pageSize);\n    }\n\n    public Page page() {\n        checkPagination();\n        return page;\n    }\n\n    private void checkPagination() {\n        if (page == null && keyedPage == 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    private void checkRange() {\n        if (range == null) {\n            throw new UnsupportedOperationException(\"Cannot call a range related method, \" +\n                    \"call range(int, int) to initiate range first\");\n        }\n        if (page != null) {\n            throw new UnsupportedOperationException(\"Cannot call a range related method in a paged query, \" +\n                    \"call range(int, int) to initiate range first\");\n        }\n    }\n\n    public Range range() {\n        checkRange();\n        return range;","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java#L273-L309","documentation":"Panache queries cannot mix range(int,int) with page-related methods. checkPagination() throws UnsupportedOperationException when a page method is invoked on a query whose result window was defined with range().","triggerScenarios":"Calling query.range(from, to) and then nextPage(), previousPage(), firstPage(), lastPage(), hasNextPage(), hasPreviousPage() or page() on the same query.","commonSituations":"Code that used range() for one-off windows later extended with paging logic; mixed pagination styles across refactors.","solutions":["Replace range(from, to) with page(pageIndex, pageSize) and use page-related methods.","Keep range() queries free of page methods; use list() to get results directly.","Create two separate queries if you need both a range window and paginated access."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").range(0, 49);\nq.hasNextPage(); // throws\n\n// after\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").page(0, 50);\nq.hasNextPage();","handlingStrategy":"validation","validationCode":"if (query instanceof rangedQuery) { // don't call page methods on range queries\n    throw new IllegalStateException(\"Use page() instead of range() to enable page methods\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    q.hasNextPage();\n} catch (UnsupportedOperationException e) {\n    // re-create the query with .page(pageIndex, pageSize) instead of range()\n}","preventionTips":["Pick range() or page() per query, never both.","Document that range() disables page-navigation methods.","Convert range windows to page(Page.of(from / size, size)) when page methods are needed."],"tags":["panache","pagination","range","unsupported-operation"],"backgroundTag":"pagination-range-conflict","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"}