quarkusio/quarkus · error · RuntimeException

Incorrect order of results

Error message

Incorrect order of results

What it means

RuntimeException thrown by listExistingPersons when the ordered result list does not start with the Person named 'Gizmo'. The CriteriaQuery applies orderBy(cb.asc(from.get("name"))) and the test expects alphabetical order, so 'Gizmo' must be first; this validates that ordering is preserved and the cached query result is correct.

Source

Thrown at integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java:531

        });

        assertRegionStats(new Counts(0, 0, 3, 4), Pokemon.class.getName());
    }

    private static void listExistingPersons(EntityManager em) {
        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);
        q.setHint("org.hibernate.cacheable", Boolean.TRUE);
        List<Person> allpersons = q.getResultList();
        if (allpersons.size() != 4) {
            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);
    }

    private void testReadWrite() {
        //Store some well known Pokemon instances we can then test on:
        storeTestPokemons(new Counts(3, 0, 0, 3));

        //Load all persons and run some checks on the cache hits
        verifyFindByIdPokemons(new int[] { 2555, 3670, 3219 }, new Counts(0, 3, 0, 3));

        //Rebalance cp values for pokemons
        rebalanceCpsForPokemons(new Counts(3, 3, 0, 3));

View on GitHub (pinned to e1c734241f)

Solutions

  1. Reset the database to the canonical seed dataset before the test so 'Gizmo' is alphabetically first
  2. Invalidate the query cache region so ordering is recomputed from current data
  3. Verify no extra Person rows exist (count check precedes this assertion - fix that first if it fails)
  4. Check DB collation/locale settings that could reorder names

Example fix

// before
if (!allpersons.get(0).getName().equals("Gizmo")) {
    throw new RuntimeException("Incorrect order of results");
}
// after
if (!allpersons.get(0).getName().equals("Gizmo")) {
    throw new RuntimeException("Incorrect order of results: first=" + allpersons.get(0).getName());
}
Defensive patterns

Strategy: validation

Validate before calling

List<String> names = em.createQuery("SELECT p.name FROM Person p ORDER BY p.name", String.class)
    .setHint("org.hibernate.cacheable", Boolean.FALSE)
    .getResultList();
if (!"Gizmo".equals(names.isEmpty() ? null : names.get(0)))
    throw new IllegalStateException("First person is not Gizmo: " + (names.isEmpty() ? "none" : names.get(0)));

Try / catch

try {
    listExistingPersons();
} catch (RuntimeException e) {
    if (e.getMessage().contains("Incorrect order of results")) {
        // evict query cache region and re-run to recompute ordering
    }
}

Prevention

When it happens

Trigger: The first element of the cacheable, name-ordered Person query is not 'Gizmo': data with different names was inserted, the query cache holds a result from a differently-ordered/older dataset, or the DB collation orders names differently than the test expects.

Common situations: Leftover rows from previous runs changing the alphabetical first entry; query cache stale after data mutation; locale/collation differences between environments altering string ordering; seed data names changed.

Related errors


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