quarkusio/quarkus · error · RuntimeException

Incorrect number of results

Error message

Incorrect number of results

What it means

This is a hand-written assertion inside the Quarkus jpa-mysql integration test endpoint. After running a Criteria API query selecting all Person entities ordered by name, the test expects exactly 3 rows; if the persistence layer returned a different count, it throws this RuntimeException. It signals that data setup, persistence, or the query did not behave as expected.

Source

Thrown at integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java:52

        //Store some well known Person instances we can then test on:
        QuarkusTransaction.requiringNew().run(() -> {
            persistNewPerson("Gizmo");
            persistNewPerson("Quarkus");
            persistNewPerson("Hibernate ORM");
        });

        //Load all persons and run some checks on the query results:
        QuarkusTransaction.requiringNew().run(() -> {
            CriteriaBuilder cb = em.getCriteriaBuilder();

            CriteriaQuery<Person> cq = cb.createQuery(Person.class);
            Root<Person> from = cq.from(Person.class);
            cq.select(from).orderBy(cb.asc(from.get("name")));
            TypedQuery<Person> q = em.createQuery(cq);
            List<Person> allpersons = q.getResultList();
            if (allpersons.size() != 3) {
                throw new RuntimeException("Incorrect number of results");
            }
            if (!allpersons.get(0).getName().equals("Gizmo")) {
                throw new RuntimeException("Incorrect order of results");
            }
            StringBuilder sb = new StringBuilder("list of stored Person names:\n\t");
            for (Person p : allpersons) {
                p.describeFully(sb);
            }
            sb.append("\nList complete.\n");
            System.out.print(sb);
        });

        //Try a JPA named query:
        QuarkusTransaction.requiringNew().run(() -> {
            TypedQuery<Person> typedQuery = em.createNamedQuery(
                    "get_person_by_name", Person.class);
            typedQuery.setParameter("name", "Quarkus");
            final Person singleResult = typedQuery.getSingleResult();

View on GitHub (pinned to e1c734241f)

Solutions

  1. Inspect the actual size of allpersons and dump the Person table in MySQL to find the extra/missing rows
  2. Ensure cleanUpData() runs before seeding so repeated invocations don't accumulate rows
  3. Verify the seeding transaction committed (QuarkusTransaction.requiringNew) and no rollback occurred
  4. Rebuild the schema from scratch (drop/create) to rule out stale state

Example fix

// before
if (allpersons.size() != 3) {
    throw new RuntimeException("Incorrect number of results");
}
// after
cleanUpData(); // guarantee a clean slate before seeding
import io.quarkus.narayana.jta.QuarkusTransaction;
QuarkusTransaction.requiringNew().run(() -> seedData());
if (allpersons.size() != 3) {
    throw new RuntimeException("Incorrect number of results: " + allpersons.size());
}
Defensive patterns

Strategy: validation

Validate before calling

// before the assertion, verify DB state
List<Person> all = em.createQuery("select p from Person p", Person.class).getResultList();
if (all.size() != 3) {
    throw new IllegalStateException("Expected 3 Person rows, found " + all.size() + ": " + all.stream().map(Person::getName).toList());
}

Try / catch

try {
    q.getResultList();
} catch (RuntimeException e) {
    // log actual row count and names before rethrowing
    throw new AssertionError("criteria query returned unexpected data: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling testTestEndpoints' criteria-query path when the number of Person rows in the MySQL database differs from 3 — e.g. seed data failed to persist, the transaction rolled back, previous test runs left stale rows, or cleanup (cleanUpData) did not run before seeding.

Common situations: Database state pollution from a prior failed run, MySQL schema/dialect issues causing a partially applied persist, or HQL/Criteria mapping changes returning more or fewer rows than expected.

Related errors


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