hibernate -----Could not instantiate cache implementation异常处理(转)

  大概意思是二级缓存不可用,但是项目在开发阶段不需要启动缓存,所以就没有配置。
最后发现问题就是在这里,因为在Hibernate的bean的hbm配置文件中配置了缓存,而在hibernate的配置中没有配置提供的缓存机制,在早起的hibernate的早起版本中默认是提供ehcache的,但是在最近的版本中已经不提供默认配置了。所以必须自己手工配置。在hibernate的配置中加入如下片段即可

<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>

 

        <!-- Hibernate二级缓存配置,把sessionFactory交给spring管理(例如开事务、提交事务等) -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
         <property name="dataSource" ref="dataSource"/><!-- 把dataSource数据源注入到dataSource属性中 -->
         <property name="mappingResources">
            <list>
                 <!-- Hibernate映射元数据,可以有多个 -->
           <value>cn/general/bean/Person.hbm.xml</value>
          </list>
         </property>
         <property name="hibernateProperties"><!-- 配置Hibernate的属性信息 -->
          <value>
           hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
           hibernate.hbm2ddl.auto=update
           hibernate.show_sql=false
           hibernate.format_sql=false
           hibernate.cache.use_second_level_cache=true
           hibernate.cache.use_query_cache=false
           hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
          </value>
         </property>
        </bean> 

posted @ 2010-12-28 12:40  GeneralXU  阅读(421)  评论(0编辑  收藏  举报