读书人

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

发布时间: 2012-12-16 12:02:32 作者: rapoo

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>这样就可以啦

读书人网 >J2EE开发

热点推荐