我正在使用 memcache 作为 Hibernate 的二级缓存。我正在使用 hibernate-memcached-1.2.4、spymemcached 2.8.0 和 hibernate 4.1.4。
但是当我尝试使用它时,它给了我一个错误提示
初始会话工厂创建失败org.hibernate.cache.NoCacheRegionFactoryAvailableException:应用程序中使用了二级缓存,但没有给出属性hibernate.cache.region.factory_class,请禁用二级缓存或将正确的区域工厂类名称设置为属性hibernate .cache.region.factory_class(并确保二级缓存提供程序,例如,hibernate-infinispan,在类路径中可用)。
线程“主”java.lang.ExceptionInInitializerError 中的异常
在 Util.HibernateUtil.(HibernateUtil.java:16)
在 hibba.AccountDAOimpl.getAccount(AccountDAOimpl.java:23)
在 hibba.Connect.main(Connect.java:7)
原因: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)
在 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 更多
hibernate.cfg.xml 中写的属性是:
<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>