问题描述
当我打电话时:
entityManager.flush()
我得到了标题中提到的例外情况.
I get the exception mentioned in the title.
我正在使用 Hibernate JPA.
I am using Hibernate JPA.
推荐答案
在自己遇到这个问题并花了几个小时试图解决之后,我终于找到了原因:Spring 有一个 bug 并且无法维护事务如果同一个类有 @Service
注释用于自动装配,则使用 @Transactional
注释.
After encountering this problem myself and spending a few hours trying to get it resolved I finally found a reason for it: Spring has a bug and can't maintain transactions with @Transactional
annotation if the same class has @Service
annotation for the means of autowiring.
一旦 @Service
注释从有问题的服务类中删除,并在 XML 配置中声明了一个适当的 bean:
Once the @Service
annotation was removed from the service class in question, and an appropriate bean was declared in the XML config:
<bean id="myService" class="com.example.myapp.service.MyServiceImpl" />
问题解决了.
查看此 JIRA 错误了解更多详情.
Check this JIRA bug for more details.
这篇关于Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException:没有正在进行的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!