{"record":{"id":"7dc196bb9fc384f0","repo":"quarkusio/quarkus","slug":"incorrect-citizen-citizen-getlastname","errorCode":null,"errorMessage":"Incorrect citizen: \" + citizen.getLastname() + \", expected: \" + expected","messagePattern":"Incorrect citizen: \" \\+ citizen\\.getLastname\\(\\) \\+ \", expected: \" \\+ expected","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":201,"sourceCode":"            final NaturalIdLoadAccess<Country> loader = session.byNaturalId(Country.class);\n            loader.using(\"callingCode\", callingCode);\n            Country country = loader.load();\n            if (!country.getName().equals(expectedName))\n                throw new RuntimeException(\"Incorrect citizen: \" + country.getName() + \", expected: \" + expectedName);\n        });\n    }\n\n    private void updateNaturalId(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\", \"45989213T\");\n            Citizen citizen = loader.load();\n            String expected = \"Stark\";\n            if (!citizen.getLastname().equals(expected))\n                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);","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L183-L219","documentation":"Assertion inside updateNaturalId: the test loads Citizen with ssn 45989213T by natural id, expects lastname 'Stark', and throws this RuntimeException if the cached/loaded entity has a different lastname. This guards that the natural-id cache resolves the correct entity before the test updates its ssn.","triggerScenarios":"Running the read-write natural id test when loading ssn=45989213T returns a Citizen whose lastname is not 'Stark' — wrong seed data, stale cache entry under that ssn, or the ssn was changed by a previous run without cache eviction.","commonSituations":"Previous test run mutated the ssn (test updates it to 78902007R) and the database was not reset; cached natural-id entry now maps to a different row; seed dataset changed.","solutions":["Reset the database / re-seed Citizens before each test run","Evict the Citizen cache region before loading (sessionFactory.getCache().evict(Citizen.class))","Verify the seeded row: ssn 45989213T must map to lastname 'Stark'","Ensure tests run in isolation so updateNaturalId does not see mutations from earlier tests"],"exampleFix":"// before\nCitizen citizen = loader.load();\nString expected = \"Stark\";\n// after\nemf.unwrap(SessionFactory.class).getCache().evict(Citizen.class);\nCitizen citizen = loader.load();\nString expected = \"Stark\";","handlingStrategy":"validation","validationCode":"Citizen citizen = loader.load();\nif (citizen == null) throw new IllegalStateException(\"No Citizen with ssn 45989213T; check seeding\");\nsessionFactory.getCache().evict(Citizen.class); // ensure fresh load","typeGuard":null,"tryCatchPattern":"try {\n    updateNaturalId(counts);\n} catch (RuntimeException e) {\n    // evict regions and re-seed before retrying\n}","preventionTips":["Re-seed test data before each endpoint test run","Evict Citizen region before natural-id lookups","Run tests in isolation so ssn mutations from earlier runs don't leak"],"tags":["hibernate","natural-id","cache","test-assertion","data-seeding"],"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"}