我使用的是5.2.8的hibernate的jar包,运行的时候却报错Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
原因是配置文件中
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
用的是hibernate4
解决方法:1:将换成hibernate-core-5.2.8.Final.jar换成hibernate-core-4.2.4.Final.jar
自己运行能够成功解决问题
2:class="org.springframework.orm.hibernate5.HibernateTransactionManager"
没有解决bug,但理论上应该是可以的
注意:在出现此种错误时,会在错误界面的最下方显示如下内容:
To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties file.
很多配置问题都会出现这一错误,因此可能会误导,要非常注意,一般情况下不要那么设置。
本文介绍了解决使用Hibernate 5.2.8版本与Spring集成时出现的CouldnotopenHibernateSessionfortransaction错误的方法。主要问题在于配置文件中使用的Hibernate版本与Spring集成不兼容。解决方案包括更换为Hibernate 4版本或更改配置文件。
320

被折叠的 条评论
为什么被折叠?



