{"record":{"id":"1f3f330adcfa897d","repo":"quarkusio/quarkus","slug":"incorrect-cp-blissey-getcp","errorCode":null,"errorMessage":"Incorrect cp: \" + blissey.getCp()","messagePattern":"Incorrect cp: \" \\+ blissey\\.getCp\\(\\)","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":585,"sourceCode":"\n        assertRegionStats(expected, Pokemon.class.getName());\n    }\n\n    private void verifyFindByIdPokemons(int[] expectedCps, Counts expected) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            Pokemon igeldo = em.find(Pokemon.class, 3);\n            if (igeldo.getCp() != expectedCps[0])\n                throw new RuntimeException(\"Incorrect cp: \" + igeldo.getCp());\n\n            Pokemon godzilla = em.find(Pokemon.class, 248);\n            if (godzilla.getCp() != expectedCps[1])\n                throw new RuntimeException(\"Incorrect cp: \" + godzilla.getCp());\n\n            Pokemon blissey = em.find(Pokemon.class, 242);\n            if (blissey.getCp() != expectedCps[2])\n                throw new RuntimeException(\"Incorrect cp: \" + blissey.getCp());\n\n        });\n\n        assertRegionStats(expected, Pokemon.class.getName());\n    }\n\n    private void storeTestPokemons(Counts expected) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            final Pokemon igeldo = new Pokemon(3, \"Venusaur\", 2555);\n            em.persist(igeldo);\n            final Pokemon godzilla = new Pokemon(248, \"Tyranitar\", 3670);\n            em.persist(godzilla);\n            final Pokemon khaleesi = new Pokemon(242, \"Blissey\", 3219);\n            em.persist(khaleesi);\n\n        });","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L567-L603","documentation":"RuntimeException thrown by verifyFindByIdPokemons when the Pokemon with ID 242 ('blissey') has a cp value that does not match expectedCps[2]. It is the last of the three per-entity cp assertions and, after passing, the test also verifies cache region statistics (assertRegionStats) for the Pokemon region.","triggerScenarios":"em.find(Pokemon.class, 242).getCp() != expectedCps[2] during the verification transaction: blissey's cp was never updated, the update rolled back, or the second-level cache served a stale copy of the entity.","commonSituations":"Update phase failure leaving blissey at its original cp; stale cache entry not invalidated after update; expectedCps array built from a different baseline (e.g. values from a previous run); concurrent test runs sharing the database.","solutions":["Confirm the write phase committed blissey's cp update before verification","Check that Hibernate updated the cached entity on write (invalidation or update-through-cache)","Recompute expectedCps from the actual written values in testReadWrite","Isolate test runs with a fresh database to avoid cross-run contamination"],"exampleFix":"// before\nif (blissey.getCp() != expectedCps[2]) throw new RuntimeException(\"Incorrect cp: \" + blissey.getCp());\n// after\nif (blissey.getCp() != expectedCps[2]) throw new RuntimeException(\"Incorrect cp for blissey: \" + blissey.getCp() + \", expected: \" + expectedCps[2]);","handlingStrategy":"validation","validationCode":"Pokemon b = em.find(Pokemon.class, 242);\nif (b == null || b.getCp() != expectedCps[2])\n    throw new IllegalStateException(\"Pokemon 242 cp mismatch or missing: \" + (b == null ? \"null\" : b.getCp()));","typeGuard":"boolean hasExpectedCp(Pokemon p, int expected) { return p != null && p.getCp() == expected; }","tryCatchPattern":"try {\n    verifyFindByIdPokemons(expectedCps, expectedCounts);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Incorrect cp\")) {\n        // rerun write phase after evicting the Pokemon region\n    }\n}","preventionTips":["Verify all three updates committed as one transaction","Use assertRegionStats to confirm cache misses reflect fresh loads","Isolate test databases to avoid cross-run stale cps"],"tags":["hibernate-orm","cache","stale-data","integration-test"],"backgroundTag":"stale-cache-entity","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"}