Hibernate版本4.1.2
Encache版本2.4.3
异常信息:[main] ERROR com.ryan.HibernateUtil - Initial SessionFactory creation failed: org.hibernate.cache.NoCacheRegionFactoryAvailableException: 
Second-level cache is used in the application, 
but property hibernate.cache.region.factory_classis not gaven, 
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, available in the classpath).hibernate.cfg.xml里是这么配的:<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="cache.use_query_cache">true</property>需要的库都在classpath下了,看报错应该是hibernate.cache.region.factory_classis这个property没有配置,但是找遍了hibernate文档也没找到这个配置是什么。

解决方案 »

  1.   

    Hibernate 3.3 and higher
    ATTENTION HIBERNATE 3.2 USERS: Make sure to note the change to BOTH the property name and value.
    Use:<property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
    只在Ehcache的文档里提到了新语法
      

  2.   

    <!--  配置二级缓存的信息-->
      <!-- 应用二级缓存 -->
      <property name="hibernate.cache.use_second_level_cache">true</property>
      <!-- 缓存的驱动类 -->
      <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>这样就可以啦