quarkusio/quarkus · error · RuntimeException
Incorrect order of results
Error message
Incorrect order of results
What it means
After asserting the count, the endpoint checks the first row of the name-ordered CriteriaQuery result is 'Gizmo' (alphabetically first of Gizmo/Quarkus/Microsoft); otherwise it throws this RuntimeException. It verifies ORDER BY translation to the actual SQL Server ordering behaves as expected.
Source
Thrown at integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java:59
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
- Confirm clean data set (exactly the three seeded persons) before asserting order
- Check the database collation for the name column (e.g. use a binary/case-sensitive collation if needed)
- Verify the 'name' attribute maps to the intended column in the Person entity
- Clean the table between runs so ordering assertions are deterministic
Defensive patterns
Strategy: validation
Validate before calling
List<Person> all = em.createQuery("select p from Person p order by p.name", Person.class).getResultList();
if (!all.isEmpty() && !all.get(0).getName().equals("Gizmo")) {
throw new IllegalStateException("Unexpected first row: " + all.get(0).getName());
} Try / catch
try {
Person first = allpersons.get(0);
} catch (RuntimeException e) {
// dump names + DB collation when order assertion fails
} Prevention
- Seed deterministic data (unique names) before ordering assertions
- Check MSSQL column collation affecting ORDER BY
- Map Person.name to the intended column
- Clean stale rows so ordering is stable
When it happens
Trigger: Criteria query with orderBy(cb.asc(from.get("name"))) returns a first element whose name is not 'Gizmo' — wrong row order, collation differences, or wrong/unmapped 'name' attribute ordering.
Common situations: MSSQL collation (case-insensitive/custom) changing expected order; duplicate rows shifting order; the Person.name mapping pointing at the wrong column; stale seed data.
Related errors
- Incorrect number of results
- Wrong result from named JPA query
- Incorrect order of results
- The container image ${dockerImageName} requires you to accep
- Methods that are annotated with JPA Listener annotations sho
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/ff82e12f9e2817b1.
Report an issue: GitHub.