hibernate.cache.region.factory_class hibernate.cfg.xml中必需的

Ani*_*mar 6 memcached hibernate

我正在使用memcache作为Hibernate的二级缓存.我正在使用hibernate-memcached-1.2.4,spymemcached 2.8.0和hibernate 4.1.4.

但是当我尝试使用它时,它给了我错误的说法

    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

用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>
Run Code Online (Sandbox Code Playgroud)

Pau*_*Pau 4

这个例外是不言自明的。您必须设置 *hibernate.cache.region.factory_class* 属性。例如,使用 ehcache 将添加以下行:

<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
Run Code Online (Sandbox Code Playgroud)

  • `net.sf.ehcache.hibernate.EhCacheRegionFactory` 适用于 Hibernate 3。对于 Hibernate 4,请使用 `&lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory&lt;/property&gt;` 。有关详细信息,请参阅http://ehcache.org/documentation/2.8/integrations/hibernate (3认同)