Add EntityManager test case illustrating usage of query cache

Description

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();

Activity

Former userJanuary 16, 2015 at 11:37 PM

Fixed in master, 4.3, and 4.2 branches.

Fixed

Details

Assignee

Reporter

Components

Priority

Created January 16, 2015 at 10:22 PM
Updated January 16, 2015 at 11:37 PM
Resolved January 16, 2015 at 11:37 PM