测试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 morehibernate.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文件吗,我没配置。
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 morehibernate.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文件吗,我没配置。
解决方案 »
- 帮忙看一下是哪的错
- hibernate报错unexpected token: mo near lin
- 社区交友类网站的个人主页都可以自定义一个网页地址!请问这个怎么实现的?
- 我想问问spring+hibernate这个架构最近很"红"
- 请教 如何 做一个jsp页面 用于记录 最近一次Ant 的时间 以及状态:“成功” 或者 “失败”
- 解析类似struts配置文件的XML
- [100分2]清jFresH_MaN()(AbsolutelyFresh)进接分,其余免进
- 数据库的问题
- java项目外包承接工作室成立
- EJB的好书,请推荐,我看了<精通EJB2.0>,好薄哟!!
- java接口怎么使用
- 在线等:Spring MVC 拦截器拦截失败
改为
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory
</property>
试过的,错误还是一样。org.hibernate.cache.EhCacheRegionFactory 类包里没有,我倒的包好像有问题
改成:
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
其他代码如下:
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Student {……//junit4测试代码如下
@Test
public void testCache2() {
Session ss = HibernateUtil.getSession();
ss.beginTransaction();
Student s = (Student) ss.load(Student.class, 2);
System.out.println(s.getName());
ss.getTransaction().commit(); Session ss2 = HibernateUtil.getSession();
ss2.beginTransaction();
Student s2 = (Student) ss2.load(Student.class, 2);
System.out.println(s2.getName());
ss2.getTransaction().commit();
}