{"record":{"id":"db38066080f93c0e","repo":"quarkusio/quarkus","slug":"incorrect-number-of-results","errorCode":null,"errorMessage":"Incorrect number of results","messagePattern":"Incorrect number of results","errorType":"exception","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java","lineNumber":378,"sourceCode":"        assertRegionStats(expected, Item.class.getName());\n    }\n\n    private static void findByIdItems(EntityManager em, String[] expectedDesc) {\n        final Item i1 = em.find(Item.class, 1L);\n        if (!i1.getDescription().equals(expectedDesc[0]))\n            throw new RuntimeException(\"Incorrect description: \" + i1.getDescription() + \", expected: \" + expectedDesc[0]);\n\n        final Item i2 = em.find(Item.class, 2L);\n        if (!i2.getDescription().equals(expectedDesc[1]))\n            throw new RuntimeException(\"Incorrect description: \" + i2.getDescription() + \", expected: \" + expectedDesc[1]);\n\n        final Item i3 = em.find(Item.class, 3L);\n        if (!i3.getDescription().equals(expectedDesc[2]))\n            throw new RuntimeException(\"Incorrect description: \" + i3.getDescription() + \", expected: \" + expectedDesc[2]);\n\n        List<Item> allitems = Arrays.asList(i1, i2, i3);\n        if (allitems.size() != 3) {\n            throw new RuntimeException(\"Incorrect number of results\");\n        }\n        StringBuilder sb = new StringBuilder(\"list of stored Items names:\\n\\t\");\n        for (Item p : allitems)\n            p.describeFully(sb);\n\n        sb.append(\"\\nList complete.\\n\");\n        System.out.print(sb);\n    }\n\n    private void testQuery() {\n        //Load all persons and run some checks on the query results:\n        Map<String, Counts> counts = new TreeMap<>();\n        counts.put(Person.class.getName(), new Counts(4, 0, 0, 4));\n        counts.put(RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, new Counts(1, 0, 1, 1));\n        verifyListOfExistingPersons(counts);\n\n        //Load all persons with same query and verify query results\n        counts = new TreeMap<>();","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L360-L396","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the preceding setup transaction (testInsert etc.) and confirm Items with IDs 1-3 are actually committed before findByIdItems runs","Check the second-level cache configuration (quarkus.hibernate-orm.second-level-caching-enabled, @Cacheable on Item) and clear/invalidate caches between runs","Reset the test database to a clean state before the test (drop/recreate schema or use a fresh DB per run)","Verify entity IDs used in find() match the ones persisted in setup"],"exampleFix":"// before\nfinal Item i1 = em.find(Item.class, 1L);\n// after\nfinal Item i1 = em.find(Item.class, 1L);\nif (i1 == null) throw new RuntimeException(\"Item 1 not found - setup data missing\");","handlingStrategy":"validation","validationCode":"List<Item> items = new ArrayList<>();\nfor (long id : new long[]{1,2,3}) {\n    Item i = em.find(Item.class, id);\n    if (i == null) throw new IllegalStateException(\"Item \" + id + \" missing before verification\");\n    items.add(i);\n}\nif (items.size() != 3) throw new IllegalStateException(\"Expected 3 items\");","typeGuard":"boolean allPresent(Item... items) { return Arrays.stream(items).allMatch(Objects::nonNull); }","tryCatchPattern":"try {\n    findByIdItems();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Incorrect number of results\")) {\n        // re-seed data and clear cache, then retry\n    }\n}","preventionTips":["Assert seed data exists (non-null finds) before building expected-size lists","Reset the database and second-level cache between test phases","Keep entity IDs in setup and verification in sync via shared constants"],"tags":["hibernate-orm","cache","integration-test","assertion"],"backgroundTag":"entity-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}