quarkusio/quarkus · error · UnsupportedOperationException
Cannot call previousPage() before fetching results with list
Error message
Cannot call previousPage() before fetching results with list()
What it means
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.
Source
Thrown at extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java:214
public void nextPage() {
checkPagination();
if (keyedPage != null) {
if (lastKeyedResult == null) {
throw new UnsupportedOperationException(
"Cannot call nextPage() before fetching results with list()");
}
keyedPage = lastKeyedResult.getNextPage();
lastKeyedResult = null;
} else {
page(page.next());
}
}
public void previousPage() {
checkPagination();
if (keyedPage != null) {
if (lastKeyedResult == null) {
throw new UnsupportedOperationException(
"Cannot call previousPage() before fetching results with list()");
}
KeyedPage<?> prev = lastKeyedResult.getPreviousPage();
if (prev != null) {
keyedPage = prev;
}
lastKeyedResult = null;
} else {
page(page.previous());
}
}
@SuppressWarnings("unchecked")
public void firstPage() {
checkPagination();
if (keyedPage != null) {
keyedPage = keyedPage.getPage().first().keyedBy((List) keyedPage.getKeyDefinition());
lastKeyedResult = null;View on GitHub (pinned to e1c734241f)
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()
Example fix
// before query.cursor(1, 20).previousPage(); // after List<Person> results = query.cursor(1, 20).list(); query.previousPage();
Defensive patterns
Strategy: try-catch
Try / catch
try {
query.previousPage();
} catch (UnsupportedOperationException e) {
if (e.getMessage() != null && e.getMessage().contains("before fetching results")) {
query.list(); // establish cursor state first
} else throw e;
} Prevention
- 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
When it happens
Trigger: Calling query.cursor(...).previousPage() before any .list() invocation on the same PanacheQuery instance.
Common situations: 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.
Related errors
- Cannot call nextPage() before fetching results with list()
- Cursor-based pagination is not supported by Hibernate Reacti
- Cursor-based pagination is not supported by Hibernate Reacti
- Cannot use cursor-based pagination without sort criteria: us
- Cannot navigate to last page in cursor-based pagination
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d5b948d82b7b8ef5.
Report an issue: GitHub.