quarkusio/quarkus · error · RuntimeException
Wrong result from named JPA query
Error message
Wrong result from named JPA query
What it means
A RuntimeException thrown when a named query 'get_person_by_name' with parameter name='Quarkus' does not return an entity whose name equals 'Quarkus'. The named query is defined in the test's XML mapping (orm.xml), so a mismatch usually means the XML mapping or data is off.
Source
Thrown at integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:102
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
- Inspect the 'get_person_by_name' named query in orm.xml and confirm it filters by name correctly
- Clean the Person table so only the expected 'Quarkus' row matches
- Enable SQL logging to verify the query executed against the expected table/columns
Example fix
// before (orm.xml) <named-query name="get_person_by_name"><query>select p from Person p</query></named-query> // after <named-query name="get_person_by_name"><query>select p from Person p where p.name = :name</query></named-query>
Defensive patterns
Strategy: validation
Validate before calling
boolean quarkusPresent = em.createQuery("select count(p) from Person p where p.name = 'Quarkus'", Long.class)
.getSingleResult() == 1; Prevention
- Keep named queries in orm.xml reviewed alongside schema changes
- Clean the table before asserting getSingleResult
- Prefer asserting row count before getSingleResult to get clearer errors
When it happens
Trigger: em.createNamedQuery("get_person_by_name", Person.class).setParameter("name", "Quarkus").getSingleResult() returns an entity with a different name - the XML-defined query selects the wrong column/alias or the DB contains different data.
Common situations: orm.xml edits that broke the JPQL, person table containing stale rows so getSingleResult picks a different row, or schema mismatch between XML mapping and actual DB columns.
Related errors
- The named query '${namedQuery}' must be defined on your JPA
- The named query '${namedQuery}' must be defined on your JPA
- Wrong result from named JPA query
- Wrong result from named JPA query
- Wrong result from named JPA query
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/e74be67b348d9fb5.
Report an issue: GitHub.