如何在Hibernate 4.1.5 SP1中配置二级缓存? [英] How to configure second level cache in Hibernate 4.1.5 SP1?

查看:188
本文介绍了如何在Hibernate 4.1.5 SP1中配置二级缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读关于此主题的其他线程,但没有解决方案适用于我。



我试着将它放在我的hibernate.cfg.xml中:

 < property name =hibernate.cache.region.factory_class> org.hibernate.cache.spi.EntityRegion< /性> 

我总是得到这个错误:
无法实例化RegionFactory [org.hibernate .cache.spi.EntityRegion]



我也尝试了Hibernate网站上线程的大部分建议,但没有成功。



那么我该如何配置呢?

解决方案

嗯,我找到了答案(来自Youtube用户):


  1. 使用hibernate-release-4.1.0.Final或更高版本。

  2. 从lib \optional\ehcache目录

  3. 更新 hibernate.cfg.xml

     < property name =cache.region.factory_class> org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory< / property> 


  4. 添加slf4j-api-1.6.1.jar(我在ehcache-2.5 .1-distribution.tar.gz
    由eHcache.org下载)因为ClassNotFoundException。


  5. 将此添加到您的hibernate.cfg中。 xml:

     <! - 启用Hibernate的自动会话上下文管理 - > 
    < property name =cache.use_second_level_cache> true< / property>


关键在于添加ehcache jar从Hibernate4中可选的\目录。


I have read other threads on here about this subject but none of the solutions work for me.

I tried putting this in my hibernate.cfg.xml:

<property name="hibernate.cache.region.factory_class">org.hibernate.cache.spi.EntityRegion</property>

I always get this error: could not instantiate RegionFactory [org.hibernate.cache.spi.EntityRegion]

I also tried most suggestions from threads on Hibernate websites but no luck.

So how do I configure this?

解决方案

Well, I found the answer (from a Youtube user):

  1. Use hibernate-release-4.1.0.Final or later versions.
  2. Add jars from lib\optional\ehcache directory
  3. Update hibernate.cfg.xml:

    <property name="cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
    

  4. Add slf4j-api-1.6.1.jar (I found it in ehcache-2.5.1-distribution.tar­.gz downloaded from ehcache.org in addition) because of ClassNotFoundException.

  5. Add this to your hibernate.cfg.xml:

    <!-- Enable Hibernate's automatic session context management -->
    <property name="cache.use_second_level_cache">true</property>
    

The key point here was adding the ehcache jar from the optional\ directory in Hibernate4.

这篇关于如何在Hibernate 4.1.5 SP1中配置二级缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆