频道栏目
IT货架 > > 正文
hibernate 二级缓存怎么配置
网友分享于:Jun 12, 2018 10:50:44 PM    来源: IT货架   
hibernate 二级缓存如何配置
测试hibeinate的二级缓存,hibernate 4.1.1 Myeclipse 8.6.出现以下异常:

at com.hsp.view.TestMain.main(TestMain.java:28)
Caused by: 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).
at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:69)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:347)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778)
at com.hsp.util.HibernateUtil.<clinit>(HibernateUtil.java:23)
... 1 more

hibernate.cfg.xml 如下:
<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:orcl
</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="myeclipse.connection.profile">
myoralce
</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>

<!-- 配置二级缓存 ,启用二级缓存-->
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
<!-- 指定使用哪种二级缓存 -->
<property name="cache.provider_class">org.hibernate.cache.internal.EhCacheProvider</property>
<mapping resource="com/hsp/domain/Department.hbm.xml" />
<mapping resource="com/hsp/domain/Student.hbm.xml" />

<class-cache class="com.hsp.domain.Student" usage="read-write"/>
</session-factory>

</hibernate-configuration>

我发现org.hibernate.cache.internal包中并没有EhCacheProvider这个类,是这个原因导致的吗?还有需要配置ehcache.xml文件吗,我没配置。

------解决方案--------------------
<property name="cache.provider_class">org.hibernate.cache.internal.EhCacheProvider</property>
改为
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory 
</property>

广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1