quarkusio/quarkus · error · UnsupportedOperationException
Cannot call a page related method, call page(Page) or page(i
Error message
Cannot call a page related method, call page(Page) or page(int, int) to initiate pagination first
What it means
Page navigation methods on PanacheQuery require that pagination was initialized via page(Page)/page(int,int). checkPagination throws UnsupportedOperationException if page is null, and a second variant if a range was set instead (range and paging are mutually exclusive).
Source
Thrown at extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java:200
public Uni<Integer> pageCount() {
checkPagination();
return count().map(count -> {
if (count == 0)
return 1; // a single page of zero results
return (int) Math.ceil((double) count / (double) page.size);
});
}
public Page page() {
checkPagination();
return page;
}
private void checkPagination() {
// FIXME: turn into Uni
if (page == null) {
throw new UnsupportedOperationException("Cannot call a page related method, " +
"call page(Page) or page(int, int) to initiate pagination first");
}
if (range != null) {
throw new UnsupportedOperationException("Cannot call a page related method in a ranged query, " +
"call page(Page) or page(int, int) to initiate pagination first");
}
}
public Range range() {
checkRange();
return range;
}
public void range(int startIndex, int lastIndex) {
this.range = Range.of(startIndex, lastIndex);
// reset the page to its default to be able to switch from page to range
this.page = null;
}View on GitHub (pinned to e1c734241f)
Solutions
- Call query.page(Page.of(index, size)) (or page(index, size)) before any page-navigation method
- Do not mix range() with page methods — pick one paging style
- Guard the navigation calls behind a check that paging was initialized
Example fix
// before
PanacheQuery<Person> q = Person.find("active");
boolean more = q.hasNextPage();
// after
PanacheQuery<Person> q = Person.find("active").page(Page.of(0, 20));
boolean more = q.hasNextPage(); Defensive patterns
Strategy: validation
Validate before calling
PanacheQuery<Person> q = Person.find("active");
if (!isPaged(q)) q.page(Page.of(0, 20)); Type guard
static boolean isPaged(PanacheQuery<?> q) {
try { q.pageCount(); return true; }
catch (UnsupportedOperationException e) { return false; }
} Try / catch
try {
return q.nextPage();
} catch (UnsupportedOperationException e) {
if (e.getMessage() != null && e.getMessage().contains("initiate pagination first")) {
return q.page(Page.of(0, 20)).nextPage();
}
throw e;
} Prevention
- Always call page(Page) or page(int,int) immediately after find() when using page APIs
- Never mix range() and page() on the same query
- Encapsulate query construction so paging is always initialized before navigation
When it happens
Trigger: Calling nextPage(), previousPage(), firstPage(), lastPage(), hasNextPage(), or hasPreviousPage() on a PanacheQuery that never had page(...) called, or on a query configured with range(from,to).
Common situations: Conditional paging code where page() is only called sometimes; calling hasNextPage() right after find() before page(); mixing range() and page() in shared query-builder code.
Related errors
- Cannot call a page related method in a ranged query, call pa
- Cannot call a range related method in a paged query, call ra
- Limiting to 0 values is not supported
- Cursor-based pagination is not supported by Hibernate Reacti
- Cannot use cursor-based pagination without sort criteria: us
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/bb8fc5b7718baa48.
Report an issue: GitHub.