{"record":{"id":"309d17c451c6abae","repo":"quarkusio/quarkus","slug":"cannot-call-a-range-related-method-in-a-paged-quer","errorCode":null,"errorMessage":"Cannot call a range related method in a paged query, call range(int, int) to initiate range first","messagePattern":"Cannot call a range related method in a paged query, call range\\(int, int\\) to initiate range 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":302,"sourceCode":"\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;\n    }\n\n    public void range(int startIndex, int lastIndex) {\n        this.range = Range.of(startIndex, lastIndex);\n        this.page = null;\n        this.keyedPage = null;\n        this.lastKeyedResult = null;\n    }\n\n    public void withLock(LockModeType lockModeType) {\n        this.lockModeType = lockModeType;","sourceCodeStart":284,"sourceCodeEnd":320,"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#L284-L320","documentation":"Panache queries cannot mix pagination with range access. checkRange() throws UnsupportedOperationException when range-related methods are used on a query that was paginated with page(Page) or page(int, int).","triggerScenarios":"Calling query.page(...) and then range() accessor or range(int,int) on the same query.","commonSituations":"Mixing pagination and range code paths; utilities that unconditionally apply range() to a query that was already paged.","solutions":["Choose one model: use page(pageIndex, pageSize) for paging or range(from, to) for a fixed window, not both.","Replace the range call with page(Page.of(0, size)) if you need a first-window equivalent.","Build a separate query instance when both windows are needed."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").page(0, 20);\nq.range(0, 49); // throws\n\n// after\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").range(0, 49); // window instead of page\n// or: .page(0, 20) and use page methods","handlingStrategy":"validation","validationCode":"if (queryWasPaged) {\n    throw new IllegalStateException(\"Do not call range() on a paged query; use page methods\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    q.range(0, 49);\n} catch (UnsupportedOperationException e) {\n    // recreate query with range() only, or use page(Page.of(0, 50))\n}","preventionTips":["Enforce a single windowing style per query instance.","Do not apply generic range() utilities to queries already built with page().","Prefer page(Page.of(...)) since it also supports page navigation."],"tags":["panache","range","pagination","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"}