{"record":{"id":"c3b07283f31e8797","repo":"quarkusio/quarkus","slug":"pokemons-should-have-been-deleted","errorCode":null,"errorMessage":"Pokemons should have been deleted","messagePattern":"Pokemons should have been deleted","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":511,"sourceCode":"\n    private void testDeleteViaRemove() {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            em.remove(em.find(Pokemon.class, 3));\n            em.remove(em.find(Pokemon.class, 248));\n            em.remove(em.find(Pokemon.class, 242));\n        });\n\n        assertRegionStats(new Counts(0, 3, 0, 4), Pokemon.class.getName());\n\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            if (em.find(Pokemon.class, 3) != null\n                    || em.find(Pokemon.class, 248) != null\n                    || em.find(Pokemon.class, 242) != null) {\n                throw new RuntimeException(\"Pokemons should have been deleted\");\n            }\n        });\n\n        assertRegionStats(new Counts(0, 0, 3, 4), Pokemon.class.getName());\n    }\n\n    private static void listExistingPersons(EntityManager em) {\n        CriteriaBuilder cb = em.getCriteriaBuilder();\n\n        CriteriaQuery<Person> cq = cb.createQuery(Person.class);\n        Root<Person> from = cq.from(Person.class);\n        cq.select(from).orderBy(cb.asc(from.get(\"name\")));\n        TypedQuery<Person> q = em.createQuery(cq);\n        q.setHint(\"org.hibernate.cacheable\", Boolean.TRUE);\n        List<Person> allpersons = q.getResultList();\n        if (allpersons.size() != 4) {\n            throw new RuntimeException(\"Incorrect number of results\");\n        }","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L493-L529","documentation":"RuntimeException thrown by testDeleteViaRemove when em.remove() was expected to delete Pokemons 3, 248 and 242 but a subsequent em.find() still returns a non-null entity. The test validates that explicit remove() deletes rows and evicts the corresponding second-level cache entries (expected Counts(0,0,3,4) misses/evictions).","triggerScenarios":"em.find(Pokemon.class, 3/248/242) returns non-null inside the verification transaction after the remove phase, so the code throws 'Pokemons should have been deleted'. Typically the remove was rolled back, ran on detached instances, or a cached entity is served from a region that was not evicted.","commonSituations":"remove() called on a detached entity without the entity being managed in the same transaction; remove transaction not committed; second-level cache region for Pokemon retaining entities after delete; test ordering issues leaving stale rows from earlier phases.","solutions":["Ensure each Pokemon is merged/managed within the same transaction before em.remove() and that the transaction commits","Verify the second-level cache eviction occurs on remove (check assertRegionStats counts for the Pokemon region)","Confirm entity IDs 3, 248, 242 are the ones actually removed (not other IDs)","Reset the DB and cache statistics between test phases (clearStatistics is already called - verify it clears all regions)"],"exampleFix":"// before\nem.remove(em.find(Pokemon.class, 3));\n// after\nPokemon p = em.find(Pokemon.class, 3);\nif (p != null) { em.remove(p); em.flush(); }","handlingStrategy":"validation","validationCode":"boolean stillThere = em.find(Pokemon.class, 3) != null\n    || em.find(Pokemon.class, 248) != null\n    || em.find(Pokemon.class, 242) != null;\nif (stillThere) throw new IllegalStateException(\"Remove phase did not delete all target pokemons\");","typeGuard":null,"tryCatchPattern":"try {\n    testDeleteViaRemove();\n} catch (RuntimeException e) {\n    if (e.getMessage().equals(\"Pokemons should have been deleted\")) {\n        // check remove() ran on managed entities and transaction committed\n    }\n}","preventionTips":["Always remove managed entities obtained via em.find() inside the same transaction","Flush after remove to surface constraints early","Verify cache eviction counts via assertRegionStats after remove"],"tags":["hibernate-orm","cache","entity-remove","integration-test"],"backgroundTag":"delete-did-not-persist","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}