Hibernate JPA和Spring javax.persistence.TransactionRequiredException:没有事务正在进行中 [英] Hibernate JPA and Spring javax.persistence.TransactionRequiredException: no transaction is in progress
问题描述
当我致电:
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
注释后,在该服务类中声明了一个合适的bean XML配置:
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:没有事务正在进行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!