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

  1. Confirm clean data set (exactly the three seeded persons) before asserting order
  2. Check the database collation for the name column (e.g. use a binary/case-sensitive collation if needed)
  3. Verify the 'name' attribute maps to the intended column in the Person entity
  4. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/ff82e12f9e2817b1. Report an issue: GitHub.