{"record":{"id":"66219098d691f3bb","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-call-page-page","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-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java","lineNumber":287,"sourceCode":"    }\n\n    public int pageCount() {\n        checkPagination();\n        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    }","sourceCodeStart":269,"sourceCodeEnd":305,"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#L269-L305","documentation":"Page-related methods (nextPage, previousPage, firstPage, lastPage, hasNextPage, hasPreviousPage, page()) require that pagination was initiated with page(Page) or page(int, int). If neither page nor keyedPage was set, checkPagination() throws UnsupportedOperationException.","triggerScenarios":"Calling nextPage()/firstPage()/hasNextPage()/etc. on a PanacheQuery on which page(Page) or page(int, int) was never called.","commonSituations":"Forgetting to set an initial page on a repository finder; conditionally applying pagination in code paths where it was skipped.","solutions":["Call page(int pageIndex, int pageSize) before any page-related method.","Call page(Page.of(pageIndex, pageSize)) with a Page instance.","If the query uses range(int,int), switch to pagination — range and page are mutually exclusive.","Initialize Page.page() (first page) explicitly at query construction."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"status\", \"active\");\nq.nextPage(); // throws\n\n// after\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").page(0, 20);\nq.nextPage();","handlingStrategy":"validation","validationCode":"PanacheQuery<Person> q = Person.find(\"active\");\nif (!q.page() initialized) { // call page() first\n    q.page(0, 20);\n}\nq.nextPage();","typeGuard":null,"tryCatchPattern":"try {\n    q.nextPage();\n} catch (UnsupportedOperationException e) {\n    q.page(Page.of(0, defaultPageSize));\n    q.nextPage();\n}","preventionTips":["Always initialize pagination with page(0, size) right after find().","Centralize query construction so page() is never skipped.","Remember range() and page() are mutually exclusive."],"tags":["panache","pagination","unsupported-operation","call-order"],"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"}