quarkusio/quarkus · error · RuntimeException

Incorrect citizen: " + citizen.getLastname() + ", expected…

Error message

Incorrect citizen: " + citizen.getLastname() + ", expected: " + expectedLastName

What it means

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.

Solutions

  1. Evict the Citizen cache region after updating the ssn or verify Hibernate's natural-id cache handles the mutation
  2. Reset/re-seed data between runs to avoid stale rows with old ssns
  3. Check the callingCode/ssn -> lastname expectations match the seeded dataset
  4. Run with a fresh in-memory cache backend to isolate the failure

Example fix

// before
citizen.setSsn("78902007R"); // then verify by new ssn
// after
citizen.setSsn("78902007R");
sessionFactory.getCache().evict(Citizen.class); // ensure no stale natural-id mapping
// then verify by new ssn
Defensive patterns

Strategy: validation

Validate before calling

Citizen citizen = loader.load();
if (citizen == null) throw new IllegalStateException("No Citizen for ssn " + ssn);
if (!citizen.getLastname().equals(expectedLastName)) {
    sessionFactory.getCache().evict(Citizen.class);
    citizen = loader.load();
}

Try / catch

try {
    verifyFindCitizenByNaturalId(ssn, expectedLastName);
} catch (RuntimeException e) {
    sessionFactory.getCache().evict(Citizen.class);
    // re-verify with clean cache to isolate cache staleness
}

Prevention

When it happens

Trigger: 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.

Common situations: Natural id cache inconsistency after mutating the natural id property; stale region data across runs; wrong expected name argument from the calling test method.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d1f287bae816b954. Report an issue: GitHub.

Appendix: source

Thrown at integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java:219

                throw new RuntimeException("Incorrect citizen: " + citizen.getLastname() + ", expected: " + expected);

            citizen.setSsn("78902007R");
        });

        assertRegionStats(counts);
    }

    private void verifyFindCitizenByNaturalId(String ssn, String expectedLastName,
            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", ssn);
            Citizen citizen = loader.load();
            if (!citizen.getLastname().equals(expectedLastName))
                throw new RuntimeException("Incorrect citizen: " + citizen.getLastname() + ", expected: " + expectedLastName);
        });

        assertRegionStats(counts);
    }

    private void storeTestCitizens(Map<String, Counts> counts) {
        clearStatistics();

        QuarkusTransaction.requiringNew().run(() -> {
            em.persist(new Citizen("Aria", "Stark", "45989213T"));
            em.persist(new Citizen("Jon", "Snow", "96246496Y"));
            em.persist(new Citizen("Tyrion", "Lannister", "09287101T"));
        });

        assertRegionStats(counts);
    }

    private void testCollection() {

View on GitHub (pinned to e1c734241f)