Second-Level Cache, Query Cache, Providers, Eviction and Configuration
Learn Second-Level Cache, Query Cache, Providers, Eviction and Configuration (Phase 6 · Hibernate Caching (Essential), Hibernate) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
The second-level (L2) cache • The second-level cache is optional and shared across sessions within a SessionFactory (an application instance). Hibernate stores entity state ("dehydrated" column values) by id; a find() miss in L1 checks L2 before the database. Reduces DB reads for read-mostly reference data (countries, categories, courses catalogue). • Lookup order for find(id) : L1 (session) → L2 (SessionFactory) → database . • It must be enabled and each entity/collection opted in. Cached state is invalidated automatically when Hibernate changes the entity (but not by external SQL, bulk...