Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException:没有正在进行的事务 [英] Hibernate JPA and Spring javax.persistence.TransactionRequiredException: no transaction is in progress

查看:26
本文介绍了Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException:没有正在进行的事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打电话时:

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:没有正在进行的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆