gpt4 book ai didi

java - Hibernate 5.2 和 Spring 4.3,非 JPA - javax.persistence.TransactionRequiredException : no transaction is in progress

转载 作者:行者123 更新时间:2023-11-29 07:31:27 25 4
gpt4 key购买 nike

将我的应用程序从 hibernate 5.1 升级到 5.2.6 时,我看到以下错误。具体来说,这是 spring 4.3.5。

javax.persistence.TransactionRequiredException: no transaction is in progress
org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3450)
org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1418)
org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1414)
org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:144)
org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)
org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:932)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
com.sun.proxy.$Proxy140.mapUserFromContext(Unknown Source)
org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider.authenticate(AbstractLdapAuthenticationProvider.java:87)

正如您在下面的堆栈跟踪中看到的,spring 显然已经启动了一个事务,并且实际上是在提交它的事务之前尝试触发刷新。同步 hibernate 和 spring 事务的代码似乎不适用于 hibernate 5.2(看起来位于 org.springframework.orm.hibernate5.SpringSessionContext.currentSession() 的末尾)。这是一个开放的错误,还是我在某处缺少配置?

最佳答案

在我的例子中,问题是由使用 Spring 的 JDBC TransactionManager 实现的旧配置设置引起的,而不是由适当的 Hibernate 集成设置引起的。这对于 Hibernate 4.1 显然是可以接受的,但对于 5.2 则不行。解决方法是将我的事务管理器 bean 声明更改为:

<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

关于java - Hibernate 5.2 和 Spring 4.3,非 JPA - javax.persistence.TransactionRequiredException : no transaction is in progress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41559793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com