{"record":{"id":"c08e4eca0a23c52b","repo":"quarkusio/quarkus","slug":"cannot-call-a-range-related-method-in-a-paged-quer-c08e4e","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-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java","lineNumber":226,"sourceCode":"\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, \" +\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 void withLock(LockModeType lockModeType) {\n        this.lockModeType = lockModeType;\n    }\n\n    public void withHint(String hintName, Object value) {\n        if (hints == null) {\n            hints = new HashMap<>();\n        }\n        hints.put(hintName, value);\n        throw new UnsupportedOperationException(\"Hints not supported yet\");\n    }\n\n    // Results\n","sourceCodeStart":208,"sourceCodeEnd":244,"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#L208-L244","documentation":"Thrown by CommonAbstractPanacheQueryImpl.checkRange when a range-related method is called on a query that is in paged mode (page != null). Panache queries support either pagination (page(Page)) or a fixed range (range(int,int)), never both at once; switching from page to range resets the page, but the reverse mix triggers this error. It is an UnsupportedOperationException for incompatible query configuration.","triggerScenarios":"Calling range(int,int) (or range accessor) on a PanacheQuery on which page(Page) or page(int,int) was previously called without any way to have cleared paging state; interleaving paging and ranging helpers on the same query object.","commonSituations":"Refactored code that switched a query from page() to range() but left page-related calls in place, or utility code that applies range() to a query already configured by a caller with page().","solutions":["Remove the page(...) call so the query is not in paged mode before applying range(int,int).","Choose one mode: use page(int,int) + page accessors for pagination, or range(int,int) alone for a one-shot window.","Use a fresh PanacheQuery instance for the ranged variant instead of reusing a paged one."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18).page(0, 20);\nq.range(0, 50); // UnsupportedOperationException\n\n// after\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18).range(0, 50);","handlingStrategy":"validation","validationCode":"if (isPaged(query)) { throw new IllegalStateException(\"Cannot apply range to a paged query\"); } // keep a boolean when you call .page(...)","typeGuard":null,"tryCatchPattern":"try { query.range(start, end); } catch (UnsupportedOperationException e) { query = baseQuery().range(start, end); }","preventionTips":["One mode per query: choose page() or range() at construction time","Create a fresh PanacheQuery from the base find()/query() when switching modes","Encapsulate paging vs ranging in repository helpers so callers cannot mix them"],"tags":["panache","hibernate-reactive","range","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"}