hibernate.cache.region.factory_class在hibernate.cfg.xml中必需 [英] hibernate.cache.region.factory_class Required in hibernate.cfg.xml
问题描述
我正在使用memcache作为Hibernate的二级缓存。我使用hibernate-memcached-1.2.4,spymemcached 2.8.0和hibernate 4.1.4。
但是当我尝试使用它时,它给了我错误, / b>
创建初始会话工厂failedorg.hibernate.cache.NoCacheRegionFactoryAvailableException:在应用程序中使用二级缓存,但属性hibernate.cache没有给出.region.factory_class,请禁用第二级缓存或将正确的区域工厂类名称设置为属性hibernate.cache.region.factory_class(并确保例如第二级缓存提供程序hibernate-infinispan可用类路径)。
异常的线程Util.HibernateUtil 主 java.lang.ExceptionInInitializerError
。(HibernateUtil.java:16)
在hibba.AccountDAOimpl.getAccount(AccountDAOimpl.java:23)$ B在hibba.Connect.main(Connect.java:7)
$ b引起的:org.hibernate.cache.NoCacheRegionFactoryAvailableException:二级缓存应用程序中使用,但产权hibernate.cache.region.factory_class是没有给出,请禁用二级缓存或将正确的区域工厂类名称设置为属性hibernate.cache.region.factory_class(并确保例如二级缓存提供程序hibernate-infinispan在类路径中可用)。
在org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:87)$ B $在org.hibernate.cache.spi.UpdateTimestampsCache湾(UpdateTimestampsCache.java:63)
。在org.hibernate.internal.SessionFactoryImpl(SessionFactoryImpl.java:510)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)
在org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java:1782)
在Util.HibernateUtil。(HibernateUtil.java:12)
... 2 more
在hibernate.cfg.xml中编写的属性为:
< pre>
< property name =hibernate.cache.use_query_cache> true< / property>
< property name =cache.provider_class> com.googlecode.hibernate.memcached.MemcachedCacheProvider< / property>
将属性名= hibernate.memcached.memcacheClientFactory > com.googlecode.hibernate.memcached.dangamemcached.DangaMemcacheClientFactory< /性>
< property name =hibernate.Memcached.servers> localhost:11211< / property>
< property name =hibernate.Memcached.cacheTimeSeconds> 300< / property>
< property name =hibernate.Memcached.connectionFactory> KetamaConnectionFactory< / property> < /预>
这个例外很容易理解。你必须设置* hibernate.cache.region.factory_class *属性。例如,ehcache会添加以下行:
< property name =hibernate.cache.region.factory_class> ; net.sf.ehcache.hibernate.EhCacheRegionFactory< /性>
I am working on using memcache as second level cache for Hibernate. I am using hibernate-memcached-1.2.4, spymemcached 2.8.0 and hibernate 4.1.4.
But when i try to use it , it gives me error saying
Initial sessionfactory creation failedorg.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given, 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, is available in the classpath). Exception in thread "main" java.lang.ExceptionInInitializerError at Util.HibernateUtil.(HibernateUtil.java:16) at hibba.AccountDAOimpl.getAccount(AccountDAOimpl.java:23) at hibba.Connect.main(Connect.java:7) Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given, 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, is available in the classpath). at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:87) at org.hibernate.cache.spi.UpdateTimestampsCache.(UpdateTimestampsCache.java:63) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:510) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782) at Util.HibernateUtil.(HibernateUtil.java:12) ... 2 more
The properties written in hibernate.cfg.xml is:
<pre>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider </property>
<property name="hibernate.memcached.memcacheClientFactory">com.googlecode.hibernate.memcached.dangamemcached.DangaMemcacheClientFactory</property>
<property name="hibernate.Memcached.servers"> localhost:11211 </property>
<property name="hibernate.Memcached.cacheTimeSeconds">300</property>
<property name="hibernate.Memcached.connectionFactory">KetamaConnectionFactory</property> </pre>
The exception is quite self-explanatory. You have to set the *hibernate.cache.region.factory_class* property. For instance with ehcache would be adding the following line:
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
这篇关于hibernate.cache.region.factory_class在hibernate.cfg.xml中必需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!