quarkusio/quarkus · error · RuntimeException
Incorrect number of results
Error message
Incorrect number of results
What it means
Same assertion as the MySQL variant, but in the jpa-postgresql integration test endpoint (RAISED IN base, a public test endpoint method). A Criteria query for all Person entities ordered by name returned a list whose size is not the expected 3, so the endpoint throws.
Source
Thrown at integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:63
//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
- Dump the person table in PostgreSQL to compare actual vs expected rows
- Run cleanUpData() before seeding to make the test idempotent
- Wrap seeding in QuarkusTransaction.requiringNew() so it commits before the query
- Reset the test database/container between runs
Example fix
// before
if (allpersons.size() != 3) {
throw new RuntimeException("Incorrect number of results");
}
// after
cleanUpData();
QuarkusTransaction.requiringNew().run(() -> seedData());
if (allpersons.size() != 3) {
throw new RuntimeException("Incorrect number of results: " + allpersons.size());
} Defensive patterns
Strategy: validation
Validate before calling
long count = (Long) em.createQuery("select count(p) from Person p").getSingleResult();
if (count != 3) {
throw new IllegalStateException("Expected 3 Person rows, found " + count);
} Try / catch
try {
q.getResultList();
} catch (RuntimeException e) {
throw new AssertionError("unexpected Person row count in PostgreSQL: " + e.getMessage(), e);
} Prevention
- Clean and re-seed the database at the start of each endpoint invocation
- Use container-per-test lifecycle so each run starts from a fresh PostgreSQL
- Include actual row count in assertion messages
When it happens
Trigger: GET to the base test endpoint while the PostgreSQL database holds a Person count other than 3 at query time — failed seeding, leftover rows from prior runs, or cleanup not executed.
Common situations: Stale PostgreSQL test database state, container-based test DB not reset between runs, or seed transaction rolled back silently.
Related errors
- Incorrect number of results
- Wrong result from named JPA query
- Incorrect number of results
- Person Quarkus doesn't exist when it should
- Wrong result from named JPA query
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/637cf326e57cc58f.
Report an issue: GitHub.