// get entities from the cache and ensure their versions are as
// expected.
EntityManager em = getEntityManagerFactory().createEntityManager();
em = getEntityManagerFactory().createEntityManager();
CacheableEntity ceFromEM = em.find(CacheableEntity.class, 1);
XmlCacheableEntity xceFromEM = em.find(XmlCacheableEntity.class, 1);
em.close();
assertEquals(cacheUpdatedForTran1 ? version + 1 : version, ceFromEM.getVersion());
assertEquals(cacheUpdatedForTran2 ? version + 1 : version, xceFromEM.getVersion());
// get the data from the database. Version should always have been
// updated in this case.
em = getEntityManagerFactory().createEntityManager();
em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.BYPASS);
CacheableEntity ceFromDB =
(CacheableEntity) em.createNativeQuery("Select * from CacheableEntity where ID = 1", CacheableEntity.class)
.getSingleResult();
XmlCacheableEntity xceFromDB =
(XmlCacheableEntity) em.createNativeQuery("Select * from XmlCacheableEntity where ID = 1",
XmlCacheableEntity.class).getSingleResult();
assertEquals(version + 1, ceFromDB.getVersion());
assertEquals(version + 1, xceFromDB.getVersion());
em.close();
}