下面列出了怎么用org.hibernate.ejb.HibernateEntityManagerFactory的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void createQueryCacheAndEvictAllThenRetry() throws Exception {
List<Author> beforeResults = getAuthorsWithQuery("Author query", "어느나라");
log.warn("#####################################################################");
HibernateEntityManagerFactory entityManagerFactory = (HibernateEntityManagerFactory) EntityTestUtils.getEntityManagerFactory();
org.hibernate.Cache cache = entityManagerFactory.getSessionFactory().getCache();
cache.evictEntityRegions();
cache.evictQueryRegions();
cache.evictDefaultQueryRegion();
cache.evictCollectionRegions();
log.warn("just eviected all.");
List<Author> againResults = getAuthorsWithQuery("Author query again after evict all", "어느나라");
assertThat(againResults).isEqualTo(beforeResults);
log.warn("#####################################################################");
}
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory);
}
/**
* 根据jpa EntityManagerFactory 获取 hibernate SessionFactory API
*
* @param emf
* @return
*/
public static SessionFactory getSessionFactory(EntityManagerFactory emf) {
return ((HibernateEntityManagerFactory) emf).getSessionFactory();
}