{"record":{"id":"d5b948d82b7b8ef5","repo":"quarkusio/quarkus","slug":"cannot-call-previouspage-before-fetching-results","errorCode":null,"errorMessage":"Cannot call previousPage() before fetching results with list()","messagePattern":"Cannot call previousPage\\(\\) before fetching results with list\\(\\)","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":214,"sourceCode":"    public void nextPage() {\n        checkPagination();\n        if (keyedPage != null) {\n            if (lastKeyedResult == null) {\n                throw new UnsupportedOperationException(\n                        \"Cannot call nextPage() before fetching results with list()\");\n            }\n            keyedPage = lastKeyedResult.getNextPage();\n            lastKeyedResult = null;\n        } else {\n            page(page.next());\n        }\n    }\n\n    public void previousPage() {\n        checkPagination();\n        if (keyedPage != null) {\n            if (lastKeyedResult == null) {\n                throw new UnsupportedOperationException(\n                        \"Cannot call previousPage() before fetching results with list()\");\n            }\n            KeyedPage<?> prev = lastKeyedResult.getPreviousPage();\n            if (prev != null) {\n                keyedPage = prev;\n            }\n            lastKeyedResult = null;\n        } else {\n            page(page.previous());\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public void firstPage() {\n        checkPagination();\n        if (keyedPage != null) {\n            keyedPage = keyedPage.getPage().first().keyedBy((List) keyedPage.getKeyDefinition());\n            lastKeyedResult = null;","sourceCodeStart":196,"sourceCodeEnd":232,"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#L196-L232","documentation":"As with nextPage(), previousPage() in keyed pagination needs the KeyedResult from a prior fetch to compute the previous key. Without a prior list() call there is no cursor state, so Panache throws UnsupportedOperationException.","triggerScenarios":"Calling query.cursor(...).previousPage() before any .list() invocation on the same PanacheQuery instance.","commonSituations":"Bi-directional paging UI logic that starts by requesting the previous page; reusing a query object across requests and expecting retained cursor state after it was cleared.","solutions":["Fetch the current page with .list() before calling previousPage()","Persist the cursor/key between requests instead of relying on previousPage() from scratch","For a first page request, don't call previousPage() — start with cursor(0, pageSize).list()"],"exampleFix":"// before\nquery.cursor(1, 20).previousPage();\n// after\nList<Person> results = query.cursor(1, 20).list();\nquery.previousPage();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    query.previousPage();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"before fetching results\")) {\n        query.list(); // establish cursor state first\n    } else throw e;\n}","preventionTips":["Fetch the current page with list() before requesting previousPage()","Persist cursor keys across requests instead of relying on in-memory state","Don't call previousPage() on the first page request"],"tags":["quarkus","panache","pagination","cursor"],"backgroundTag":"nextpage-before-fetch","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"}