public void testCacheRefreshModeRefresh() {
EntityManager em = emf.createEntityManager();
// Create a new cacheable entity
CacheableEntity ce = createEntity(em);
int ceid = ce.getId();
// Clear the L1
em.clear();
// Clear the L2 cache
Cache cache = emf.getCache();
cache.evictAll();
assertFalse(cache.contains(CacheableEntity.class, ceid));
// Find the entity, reloading it into the L2
em.getTransaction().begin();
ce = em.find(CacheableEntity.class, ceid);
assertTrue(em.contains(ce));
assertTrue(cache.contains(CacheableEntity.class, ceid));
assertTrue(em.getLockMode(ce) == LockModeType.NONE);
assertEquals(ce.getName(), "Cached Entity");
assertEquals(ce.getVersion(), 1);
em.getTransaction().commit();
// Create a new EMF -WITHOUT- the L2 enabled. If the L2 was enabled, the
// sjvm remote commit provider would evict the entity upon update, throwing
// off the intent of this variation.
EntityManagerFactory emf2 = this.createEMF(CacheableEntity.class,
"openjpa.LockManager", "mixed",
"openjpa.ConnectionFactoryProperties", "PrintParameters=true");
EntityManager em2 = emf2.createEntityManager();
// Find + lock, then update the entity and commit
em2.getTransaction().begin();
CacheableEntity ce2 = em2.find(CacheableEntity.class, ceid, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
ce2.setName("Updated Cached Entity");
em2.getTransaction().commit();
em2.close();
emf2.close();
// Refresh the entity - this will load the entity into the L1 and with storeMode=REFRESH,