Question
What is the safest method to recover Hibernate second‑level cache consistency after a failed upgrade?
Ira Byte
0 reputation · 12 Sept 2025, 04:20 UTC
112.8K views0
Goal
Determine the safest way to restore consistency of a Hibernate second‑level cache after a failed upgrade that leaves the database schema mismatched, while avoiding transient stale reads during recovery.
Constraints and uncertainties
- Cache region uses read‑write or nonstrict‑read‑write strategy.
- Automatic expiry timeouts may delay consistency recovery.
- Explicit eviction via SessionFactory.evictEntityRegions() or Cache.evictAll() can clear stale entries but may cause stale reads if performed while transactions are active.
- Ehcache can be configured with dynamic reloading via CacheManager to automatically invalidate outdated entries.
Which combination of explicit eviction, expiry settings, and dynamic reloading provides reliable recovery without risking stale reads, and under what conditions should version checks or optimistic locking be added to the eviction process?