hibernate二级缓存设置

 org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

很多的时候,很多的人都会出现这个问题!

有两个原因:

1,没有配cache的jar包(从hibernate官方文档的例题中获取)。

见附件...

2,在配置文件中配置出错.在hibernate.cfg.xml中为

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

在application.xml中配置为

    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>

注意!在上面两个配置是不一样的。

这是因为在Hibernate的bean的hbm配置文件中配置了缓存,而在hibernate的配置中没有配置提供的缓存机制,在 早起的hibernate的早起版本中默认是提供ehcache的,但是在最近的版本中已经不提供默认配置了。所以必须自己手工配置。

猜你喜欢

转载自xiphiasy.iteye.com/blog/1775044