IllegalArgumentException during SessionFactory initialization after failed upgrade
0 reputation · 20 Dec 2020, 20:01 UTC
Problem Context
A Hibernate upgrade that changes the dialect or mapping metadata often ends with an IllegalArgumentException during SessionFactory initialization. Existing sessions remain open until explicitly closed, creating potential resource leaks.
Key Constraints
1. The database schema may be out of sync with the new mapping, leading to second‑level cache corruption and ClassCastException on subsequent reads.
2. Automatic schema migration (e.g., hbm2ddl.auto=update) is risky in production and may require manual intervention.
Open Questions
- Should all active sessions be closed before restarting the application to prevent leaks, or can the
SessionFactorybe safely rebuilt while sessions linger? - Is invoking
SessionFactory.getCache().evictAll()sufficient to eliminate stale cache entries, or is a more granular eviction strategy needed? - What is the recommended sequence of steps—schema reconciliation, cache eviction, and session factory rebuild—to guarantee mapping consistency without data loss after a failed upgrade?