public String sameSessionCheck(String CACHE_REGION_NAME) {
EntityManager em = emf.createEntityManager();
Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
try{
// add new entities and check if they are put in 2LC
createEmployee(em, "Peter", "Ostrava", 2);
createEmployee(em, "Tom", "Brno", 3);
assertEquals("There are 2 puts in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
// loading all Employee entities should put in 2LC all Employee
List<?> empList = getAllEmployeesQuery(em);
assertEquals("There are 2 entities.", empList.size(), 2);
assertEquals("There are 2 entities in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getElementCountInMemory());
// clear session
em.clear();
// entity should be loaded from 2L cache, we'are expecting hit in 2L cache
Employee emp = getEmployee(em, 2);
assertNotNull("Employee returned", emp);
assertEquals("Expected 1 hit in cache"+generateEntityCacheStats(emp2LCStats), 1, emp2LCStats.getHitCount());
}catch (AssertionError e) {
return e.getMessage();
} finally{
em.close();