繁体   English   中英

hibernate4.LocalSessionFactoryBean无法转换为org.hibernate.cfg.Configuration

[英]hibernate4.LocalSessionFactoryBean cannot be cast to org.hibernate.cfg.Configuration

这似乎是一个常见的问题,但我无法解决。 我的Spring 3.1.1配置是

<bean id="sessionFactoryEditSolution" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="editSolutions-pool"/>
        <property name="mappingResources">
            <list>
                <value>/editsolutions.hibernate.cfg.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
                <prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>
                <prop key="hibernate.max_fetch_depth">6</prop>
                <prop key="hibernate.default_schema">dbo</prop>
            </props>
        </property>
    </bean> 

这就是我试图获取配置对象的方式

Configuration editSolutionsConfiguration = `(Configuration)AppContext.getBean("&sessionFactoryEditSolution");`

最初,我的应用程序具有Hibernate 3 ,但为了将其与Spring 3.1.1集成,我已将其升级到Hibernate4 。这就是为什么我必须将hibernate3.jar保留在我的lib文件夹中,以支持少量特定于Hibernate 3的代码行的原因。

一些注意事项:

  • 您不能在类路径上使用两个版本的休眠模式。 您的旧代码应更新
  • &x返回工厂bean,不返回生产对象。 即使没有&符,这也将返回SessionFactory ,而不是Configuration
  • 春天,您实际上不需要Configuration ,它是在后台处理的
  • 我们正在使用休眠3和Spring 3.1。 3.1.1可能有所不同,但要么保留两者的较低版本,要么对其进行升级(包括代码)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM