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

查看:159
本文介绍了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 注释后,在该服务类中声明了一个合适的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屋!

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