【发布时间】:2017-08-20 01:36:20
【问题描述】:
尝试从 4.3.11 升级到休眠 5.2.9。目前使用的是hibernate原生api。在 pom.xml 中添加依赖项后,运行单元测试时出现以下错误:
通过字段“sessionFactory”表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [testApplicationContext.xml] 中定义的名称为“sessionFactory”的 bean 时出错:调用 init 方法失败;嵌套异常是 org.hibernate.loader.MultipleBagFetchException: 不能同时获取多个包
我有一个 testApplicationContext.xml,其中包含以下内容:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="org.xxxx.xxxx.xxxx.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
我将 sessionFactory 和 transactionManager 从 hibernate4 更新为 hibernate5。
pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>
</dependency>
据我所知,错误消息暗示加载多个急切加载的集合时出现问题。但是,我从this 了解到,使用特定于休眠的注释和更新版本的休眠支持此用例。
有人可以帮忙吗?谢谢
【问题讨论】: