当前位置: 代码迷 >> J2EE >> Hibernate使用Ehcache二级缓存时的错误NoCacheRegionFactoryAvailableException
  详细解决方案

Hibernate使用Ehcache二级缓存时的错误NoCacheRegionFactoryAvailableException

热度:81   发布时间:2016-04-22 00:16:58.0
Hibernate使用Ehcache二级缓存时的异常NoCacheRegionFactoryAvailableException
Hibernate版本4.1.2
Encache版本2.4.3
异常信息:

[main] ERROR com.ryan.HibernateUtil - Initial SessionFactory creation failed: org.hibernate.cache.NoCacheRegionFactoryAvailableException: 
Second-level cache is used in the application, 
but property hibernate.cache.region.factory_classis not gaven, 
please either disable second level cache or set correct region factory class name to property hibernate.cache.region.factory_class 
(and make sure the second level cache provider, hibernate-infinispan, for example, available in the classpath).

hibernate.cfg.xml里是这么配的:

<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="cache.use_query_cache">true</property>

需要的库都在classpath下了,看报错应该是hibernate.cache.region.factory_classis这个property没有配置,但是找遍了hibernate文档也没找到这个配置是什么。
------最佳解决方案--------------------
Hibernate 3.3 and higher
ATTENTION HIBERNATE 3.2 USERS: Make sure to note the change to BOTH the property name and value.
Use:

<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory</property>


只在Ehcache的文档里提到了新语法
------其他解决方案--------------------
该回复于2012-07-27 16:45:05被版主删除
------其他解决方案--------------------
请问,楼主的问题解决了吗?
------其他解决方案--------------------
<!--  配置二级缓存的信息-->
  <!-- 应用二级缓存 -->
  <property name="hibernate.cache.use_second_level_cache">true</property>
  <!-- 缓存的驱动类 -->
  <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>这样就可以啦
  相关解决方案