{"record":{"id":"d1f287bae816b954","repo":"quarkusio/quarkus","slug":"incorrect-citizen-citizen-getlastname-d1f287","errorCode":null,"errorMessage":"Incorrect citizen: \" + citizen.getLastname() + \", expected: \" + expectedLastName","messagePattern":"Incorrect citizen: \" \\+ citizen\\.getLastname\\(\\) \\+ \", expected: \" \\+ expectedLastName","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":219,"sourceCode":"                throw new RuntimeException(\"Incorrect citizen: \" + citizen.getLastname() + \", expected: \" + expected);\n\n            citizen.setSsn(\"78902007R\");\n        });\n\n        assertRegionStats(counts);\n    }\n\n    private void verifyFindCitizenByNaturalId(String ssn, String expectedLastName,\n            Map<String, Counts> counts) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            final Session session = em.unwrap(Session.class);\n            final NaturalIdLoadAccess<Citizen> loader = session.byNaturalId(Citizen.class);\n            loader.using(\"ssn\", ssn);\n            Citizen citizen = loader.load();\n            if (!citizen.getLastname().equals(expectedLastName))\n                throw new RuntimeException(\"Incorrect citizen: \" + citizen.getLastname() + \", expected: \" + expectedLastName);\n        });\n\n        assertRegionStats(counts);\n    }\n\n    private void storeTestCitizens(Map<String, Counts> counts) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            em.persist(new Citizen(\"Aria\", \"Stark\", \"45989213T\"));\n            em.persist(new Citizen(\"Jon\", \"Snow\", \"96246496Y\"));\n            em.persist(new Citizen(\"Tyrion\", \"Lannister\", \"09287101T\"));\n        });\n\n        assertRegionStats(counts);\n    }\n\n    private void testCollection() {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L201-L237","documentation":"Assertion inside verifyFindCitizenByNaturalId: loads a Citizen by a given ssn via NaturalIdLoadAccess and throws this RuntimeException when the loaded entity's lastname differs from expectedLastName. Used by the read-write natural id test to verify that after updating the ssn, lookups by both old and new natural ids resolve the correct entity through the cache.","triggerScenarios":"After changing a Citizen's ssn, querying by the new (or old) ssn returns a cached entity with the wrong lastname — the natural-id cache was not updated/evicted correctly, or the expected value passed by the caller does not match the seeded data.","commonSituations":"Natural id cache inconsistency after mutating the natural id property; stale region data across runs; wrong expected name argument from the calling test method.","solutions":["Evict the Citizen cache region after updating the ssn or verify Hibernate's natural-id cache handles the mutation","Reset/re-seed data between runs to avoid stale rows with old ssns","Check the callingCode/ssn -> lastname expectations match the seeded dataset","Run with a fresh in-memory cache backend to isolate the failure"],"exampleFix":"// before\ncitizen.setSsn(\"78902007R\"); // then verify by new ssn\n// after\ncitizen.setSsn(\"78902007R\");\nsessionFactory.getCache().evict(Citizen.class); // ensure no stale natural-id mapping\n// then verify by new ssn","handlingStrategy":"validation","validationCode":"Citizen citizen = loader.load();\nif (citizen == null) throw new IllegalStateException(\"No Citizen for ssn \" + ssn);\nif (!citizen.getLastname().equals(expectedLastName)) {\n    sessionFactory.getCache().evict(Citizen.class);\n    citizen = loader.load();\n}","typeGuard":null,"tryCatchPattern":"try {\n    verifyFindCitizenByNaturalId(ssn, expectedLastName);\n} catch (RuntimeException e) {\n    sessionFactory.getCache().evict(Citizen.class);\n    // re-verify with clean cache to isolate cache staleness\n}","preventionTips":["Evict regions after mutating natural-id properties","Keep a single source of truth for seed rows","Clear the second-level cache between phases of the test"],"tags":["hibernate","natural-id","cache-invalidation","test-assertion","quarkus"],"backgroundTag":"stale-cache-data","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"}