quarkusio/quarkus · error · RuntimeException
Incorrect order of results
Error message
Incorrect order of results
What it means
Postgres variant of the ordering assertion: the Criteria query with orderBy(name asc) did not return 'Gizmo' as the first element. Either the ORDER BY was not applied to the SQL sent to PostgreSQL or the data set differs from the seed expectations.
Source
Thrown at integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:66
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();
if (!singleResult.getName().equals("Quarkus")) {
throw new RuntimeException("Wrong result from named JPA query");View on GitHub (pinned to e1c734241f)
Solutions
- Print allpersons names in returned order to diagnose
- Enable Hibernate SQL logging to confirm ORDER BY name asc is present
- Verify seed data names exactly match expectations
- Check the column collation/ctype of the PostgreSQL database
Example fix
// before
if (!allpersons.get(0).getName().equals("Gizmo")) {
throw new RuntimeException("Incorrect order of results");
}
// after (diagnostic)
System.out.println("order: " + allpersons.stream().map(Person::getName).toList());
if (!allpersons.get(0).getName().equals("Gizmo")) {
throw new RuntimeException("Incorrect order of results");
} Defensive patterns
Strategy: validation
Validate before calling
List<String> names = allpersons.stream().map(Person::getName).toList();
if (!Objects.equals(names.stream().sorted().findFirst().orElse(null), "Gizmo")) {
throw new IllegalStateException("First row is not 'Gizmo': " + names);
} Try / catch
try {
q.getResultList();
} catch (RuntimeException e) {
throw new AssertionError("ordered query failed: " + e.getMessage(), e);
} Prevention
- Assert on the full ordered name list, not just the first element
- Confirm ORDER BY appears in logged SQL
- Check PostgreSQL collation (LC_COLLATE) in the test container
When it happens
Trigger: Executing the ordered Criteria query in the jpa-postgresql base endpoint when the first Person row's name is not 'Gizmo' — missing ORDER BY in generated SQL, different seed names, or collation surprises.
Common situations: Locale/collation differences in the PostgreSQL instance, leftover rows with names alphabetically before 'Gizmo', or a Hibernate dialect/translation regression.
Related errors
- Incorrect order of results
- Incorrect number of results
- Wrong result from named JPA query
- Incorrect loaded MyUUIDEntity " + myEntity
- No entities with json were found
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/22ffa85d3612758a.
Report an issue: GitHub.