quarkusio/quarkus · error · RuntimeException
Incorrect citizen: " + country.getName() + ", expected: " +
Error message
Incorrect citizen: " + country.getName() + ", expected: " + expectedName
What it means
This is a test-endpoint assertion failure inside verifyFindCountryByNaturalId: after loading a Country by its natural id (callingCode) via Hibernate's NaturalIdLoadAccess, the endpoint checks the loaded entity's name matches the expected value and throws RuntimeException if not. It indicates the second-level/natural-id cache returned the wrong (stale or incorrect) entity for that natural id.
Source
Thrown at integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java:187
counts.put(Citizen.class.getName() + "##NaturalId", new Counts(1, 1, 0, 3));
updateNaturalId(counts);
counts = new TreeMap<>();
counts.put(Citizen.class.getName(), new Counts(0, 1, 0, 3));
counts.put(Citizen.class.getName() + "##NaturalId", new Counts(0, 1, 0, 3));
verifyFindCitizenByNaturalId("78902007R", "Stark", counts);
}
private void verifyFindCountryByNaturalId(String callingCode, String expectedName) {
clearStatistics();
QuarkusTransaction.requiringNew().run(() -> {
final Session session = em.unwrap(Session.class);
final NaturalIdLoadAccess<Country> loader = session.byNaturalId(Country.class);
loader.using("callingCode", callingCode);
Country country = loader.load();
if (!country.getName().equals(expectedName))
throw new RuntimeException("Incorrect citizen: " + country.getName() + ", expected: " + expectedName);
});
}
private void updateNaturalId(Map<String, Counts> counts) {
clearStatistics();
QuarkusTransaction.requiringNew().run(() -> {
final Session session = em.unwrap(Session.class);
final NaturalIdLoadAccess<Citizen> loader = session.byNaturalId(Citizen.class);
loader.using("ssn", "45989213T");
Citizen citizen = loader.load();
String expected = "Stark";
if (!citizen.getLastname().equals(expected))
throw new RuntimeException("Incorrect citizen: " + citizen.getLastname() + ", expected: " + expected);
citizen.setSsn("78902007R");
});
View on GitHub (pinned to e1c734241f)
Solutions
- Clear/invalidated the second-level cache regions before the test run (endpoint has clearStatistics; also evict entity cache)
- Verify the seeded Country data matches the expected callingCode/name mapping
- Run with a clean cache backend (fresh Caffeine/in-memory cache) to rule out stale state
- Confirm @Cache concurrency strategy (READ_ONLY) is not being violated by updates
Example fix
// before Country country = loader.load(); if (!country.getName().equals(expectedName)) throw ... // after sessionFactory.getCache().evict(Country.class); // clear stale region before load Country country = loader.load(); if (!country.getName().equals(expectedName)) throw ...
Defensive patterns
Strategy: validation
Validate before calling
Country country = loader.load();
Objects.requireNonNull(country, "No Country for callingCode " + callingCode);
if (!country.getName().equals(expectedName)) {
sessionFactory.getCache().evict(Country.class);
country = loader.load(); // reload from DB
if (!country.getName().equals(expectedName)) throw new RuntimeException("Data mismatch, not cache");
} Try / catch
try {
verifyFindCountryByNaturalId(callingCode, expectedName);
} catch (RuntimeException e) {
sessionFactory.getCache().evict(Country.class);
// retry once with a clean cache to distinguish staleness from bad data
} Prevention
- Reset/re-seed data between test runs
- Evict entity regions before cache-behavior assertions
- Keep seed data and expected values in one shared constant
When it happens
Trigger: Calling the testNaturalId (read-only) endpoint when the cache returns a Country whose name differs from the expected mapping of callingCode -> name — e.g. stale cached data or wrong entity stored under the natural id key.
Common situations: Stale second-level cache after data changes; cache not invalidated between test runs; different dataset seeded than the test expects; natural id cache region misconfigured (wrong concurrency strategy) leading to inconsistent reads.
Related errors
- Incorrect citizen: " + citizen.getLastname() + ", expected:
- Incorrect family size: " + pokemons.size() + ", expected: "
- Incorrect description: " + i1.getDescription() + ", expected
- Incorrect description: " + i2.getDescription() + ", expected
- Incorrect description: " + i3.getDescription() + ", expected
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b1ba53879b8df821.
Report an issue: GitHub.