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

  1. Call query.page(Page.of(index, size)) (or page(index, size)) before any page-navigation method
  2. Do not mix range() with page methods — pick one paging style
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/bb8fc5b7718baa48. Report an issue: GitHub.