quarkusio/quarkus · error · RuntimeException
Wrong result from named JPA query
Error message
Wrong result from named JPA query
What it means
The endpoint executes named query 'get_person_by_name' with parameter 'Quarkus' and asserts the single returned Person has name 'Quarkus'; any other value throws this RuntimeException. Same failure family as the MariaDB variant but on SQL Server — it flags wrong query mapping, wrong matched row, or data issues.
Source
Thrown at integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java:77
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();
if (!singleResult.getName().equals("Quarkus")) {
throw new RuntimeException("Wrong result from named JPA query");
}
});
//Check that HQL fetch does not throw an exception
QuarkusTransaction.requiringNew()
.run(() -> em.createQuery("from Person p left join fetch p.address a").getResultList());
cleanUpData();
return "OK";
}
private void cleanUpData() {
QuarkusTransaction.requiringNew()
.run(() -> em.createNativeQuery("Delete from Person").executeUpdate());
}
private void persistNewPerson(String name) {View on GitHub (pinned to e1c734241f)
Solutions
- Run cleanUpData before seeding to guarantee a deterministic table
- Inspect the get_person_by_name @NamedQuery WHERE clause and column mapping
- Query the table directly in SQL Server to see which rows match name='Quarkus'
- Consider a unique constraint on Person.name for test determinism
Defensive patterns
Strategy: validation
Validate before calling
List<Person> matches = em.createNamedQuery("get_person_by_name", Person.class)
.setParameter("name", "Quarkus").getResultList();
if (matches.size() != 1 || !matches.get(0).getName().equals("Quarkus")) {
throw new IllegalStateException("get_person_by_name returned unexpected data");
} Try / catch
try {
Person p = typedQuery.getSingleResult();
} catch (RuntimeException e) {
// verify named-query definition and table contents before retrying
} Prevention
- Reset table state before each test run
- Keep named queries aligned with actual column mappings
- Enforce unique constraints on queried columns
- Verify with raw SQL which rows match the filter
When it happens
Trigger: getSingleResult() of the named query returns a Person whose getName() != 'Quarkus' — the query's WHERE clause matches a different row (duplicates, wrong column) or the entity mapping is inconsistent.
Common situations: Duplicate/leftover 'Quarkus'-adjacent rows; @NamedQuery filtering on the wrong column; MSSQL collation causing unexpected matches; failed cleanup leaving older fixtures.
Related errors
- Wrong result from named JPA query
- Incorrect number of results
- Wrong result from named JPA query
- Wrong result from named JPA query
- The named query '${namedQuery}' must be defined on your JPA
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/12b1de40ca129cb7.
Report an issue: GitHub.