quarkusio/quarkus · error · RuntimeException
Incorrect number of results
Error message
Incorrect number of results
What it means
The endpoint seeds three Person rows, runs a CriteriaQuery ordered by name, and asserts exactly 3 results; a different count throws this RuntimeException. It detects leftover rows from prior runs, failed cleanup, or inserts that did not commit.
Source
Thrown at integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java:56
//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
- Ensure cleanUpData() runs before seeding at the start of each request/test
- Reset the database/container between test runs (fresh testcontainer or drop/recreate schema)
- Avoid running tests in parallel against a shared database
- Add a unique constraint or delete-by-name cleanup to make seeding idempotent
Defensive patterns
Strategy: validation
Validate before calling
long count = (long) em.createQuery("select count(p) from Person p").getSingleResult();
if (count != 0) { em.createQuery("delete from Person").executeUpdate(); } // clean before seeding Try / catch
try {
List<Person> all = q.getResultList();
} catch (RuntimeException e) {
// log actual rows: allpersons.forEach(p -> System.out.println(p.getName()));
} Prevention
- Always clean the table before seeding in tests
- Use fresh testcontainers per run instead of a persistent DB
- Disable parallel execution against shared databases
- Assert actual row contents in failure messages for debuggability
When it happens
Trigger: GET the endpoint when the Person table contains fewer or more than 3 rows at query time — duplicate seeds without cleanup, other tests inserting Persons concurrently, or seed inserts failing silently.
Common situations: Test DB shared/persistent across runs accumulating rows; cleanUpData not invoked or failing; concurrent test executions against the same MSSQL instance; container reused with stale data.
Related errors
- Incorrect order of results
- Wrong result from named JPA query
- Person Quarkus doesn't exist when it should
- Wrong result from named JPA query
- Incorrect number of results
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/45559f8b71a9d419.
Report an issue: GitHub.