quarkusio/quarkus · error · RuntimeException

Incorrect number of results

Error message

Incorrect number of results

What it means

A RuntimeException thrown by the Hibernate ORM cache integration test endpoint when the in-memory list of Items assembled from three em.find() calls does not contain exactly 3 elements. Since the list is built from three find results via Arrays.asList, a size mismatch implies one or more em.find(Item.class, id) calls returned null (the entity was not in the database or second-level cache as expected).

Source

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

        assertRegionStats(expected, Item.class.getName());
    }

    private static void findByIdItems(EntityManager em, String[] expectedDesc) {
        final Item i1 = em.find(Item.class, 1L);
        if (!i1.getDescription().equals(expectedDesc[0]))
            throw new RuntimeException("Incorrect description: " + i1.getDescription() + ", expected: " + expectedDesc[0]);

        final Item i2 = em.find(Item.class, 2L);
        if (!i2.getDescription().equals(expectedDesc[1]))
            throw new RuntimeException("Incorrect description: " + i2.getDescription() + ", expected: " + expectedDesc[1]);

        final Item i3 = em.find(Item.class, 3L);
        if (!i3.getDescription().equals(expectedDesc[2]))
            throw new RuntimeException("Incorrect description: " + i3.getDescription() + ", expected: " + expectedDesc[2]);

        List<Item> allitems = Arrays.asList(i1, i2, i3);
        if (allitems.size() != 3) {
            throw new RuntimeException("Incorrect number of results");
        }
        StringBuilder sb = new StringBuilder("list of stored Items names:\n\t");
        for (Item p : allitems)
            p.describeFully(sb);

        sb.append("\nList complete.\n");
        System.out.print(sb);
    }

    private void testQuery() {
        //Load all persons and run some checks on the query results:
        Map<String, Counts> counts = new TreeMap<>();
        counts.put(Person.class.getName(), new Counts(4, 0, 0, 4));
        counts.put(RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, new Counts(1, 0, 1, 1));
        verifyListOfExistingPersons(counts);

        //Load all persons with same query and verify query results
        counts = new TreeMap<>();

View on GitHub (pinned to e1c734241f)

Solutions

  1. Inspect the preceding setup transaction (testInsert etc.) and confirm Items with IDs 1-3 are actually committed before findByIdItems runs
  2. Check the second-level cache configuration (quarkus.hibernate-orm.second-level-caching-enabled, @Cacheable on Item) and clear/invalidate caches between runs
  3. Reset the test database to a clean state before the test (drop/recreate schema or use a fresh DB per run)
  4. Verify entity IDs used in find() match the ones persisted in setup

Example fix

// before
final Item i1 = em.find(Item.class, 1L);
// after
final Item i1 = em.find(Item.class, 1L);
if (i1 == null) throw new RuntimeException("Item 1 not found - setup data missing");
Defensive patterns

Strategy: validation

Validate before calling

List<Item> items = new ArrayList<>();
for (long id : new long[]{1,2,3}) {
    Item i = em.find(Item.class, id);
    if (i == null) throw new IllegalStateException("Item " + id + " missing before verification");
    items.add(i);
}
if (items.size() != 3) throw new IllegalStateException("Expected 3 items");

Type guard

boolean allPresent(Item... items) { return Arrays.stream(items).allMatch(Objects::nonNull); }

Try / catch

try {
    findByIdItems();
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Incorrect number of results")) {
        // re-seed data and clear cache, then retry
    }
}

Prevention

When it happens

Trigger: em.find(Item.class, 1L/2L/3L) returns null after the test data setup phase, so Arrays.asList(i1,i2,i3) has fewer than 3 non-null entries or the subsequent dereference fails; raised inside findByIdItems when allitems.size() != 3.

Common situations: Test database not populated by the setup transaction; data left over from a previous failed run (IDs not matching); second-level cache serving stale/evicted entries; transaction isolation so the find does not see committed seed data.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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