如何在Hibernate 4.1.5 SP1中配置二级缓存? [英] How to configure second level cache in 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用户):
- 使用hibernate-release-4.1.0.Final或更高版本。
- 从lib \optional\ehcache目录
-
更新
hibernate.cfg.xml
:< property name =cache.region.factory_class> org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory< / property>
-
添加slf4j-api-1.6.1.jar(我在ehcache-2.5 .1-distribution.tar.gz
由eHcache.org下载)因为ClassNotFoundException。 -
将此添加到您的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):
- Use hibernate-release-4.1.0.Final or later versions.
- Add jars from lib\optional\ehcache directory
Update
hibernate.cfg.xml
:<property name="cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
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.
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屋!