Add an EntityManager test case that illustrates second-level cache eviction expectations when using QueryHints.HINT_CACHEABLE.
EntityManagerFactory().getCache().evictAll() only evicts entity regions of the second-level cache. The collection and query cache regions are left intact. As a result, query results can still be found in the query cache, but each entity referenced in that query result will result in a "miss" because the entity itself has been evicted from the entity region of the second-level cache. Hibernate will load each "missed" entity from the database (rather than re-executing the original query to obtain all entity data).
To avoid loading each "missed" entity, the query cache region should also be evicted using:
EntityManager.unwrap( HibernateEntityManagerImplementor.class ) .getFactory() .getSessionFactory() .getCache() .evictQueryRegions();
|