博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javax.persistence.TransactionRequiredException: Executing an update/delete query
阅读量:4678 次
发布时间:2019-06-09

本文共 979 字,大约阅读时间需要 3 分钟。

这个问题出现在整合springmvc+spring4+hibernate5的时候出现的。首先事务要配好,我是这样配置的:

//之后在合适的位置添加注解(一般在实现类或方法上):@Transactional//添加事务也可以解决这个异常:Could not obtain transaction-synchronized Session for current thread

但是设置了之后事务好像没生效,在查看spring官方文档中说了这么一句:

7zFpCgn.jpg
就说如果你在springmvc中配置了<tx:annotation-driven/>,那么spring中的
<tx:annotation-driven transaction-manager="txManager"/>就失效了,他不会扫描除了controller以外的包中的有@Transactional注解的地方。

所以解决方法就是分段扫描:

SpringMVC.xml配置文件--> 只扫描controller组件 注意使用 use-default-filters="false" 
ApplicationContext.xml配置文件-->扫描除controller外的所有组件

上面方法是: 提供的。

在此之前我看过其他解决方法,如:

@Transactional所导的包是:org.springframework.transaction.annotation.Transactional

更多解决方法看下面:

  • https://stackoverflow.com/questions/24046913/not-active-transaciotn-javax-persistence-transactionrequiredexception-executin
  • https://stackoverflow.com/questions/12317904/transactionrequiredexception-executing-an-update-delete-query

转载于:https://www.cnblogs.com/myzoneliver/p/8358792.html

你可能感兴趣的文章
springmvc接收JSON类型的数据
查看>>
mybatis配置文件详解
查看>>
Objective-C plist文件与KVC 的使用
查看>>
jqGrid(2)
查看>>
杂题 UVAoj 107 The Cat in the Hat
查看>>
关于jquery-weui.js中时间控件datetimepicker的使用
查看>>
单页面应用程序(SPA)的优缺点
查看>>
http请求和http响应详细解析
查看>>
Centos 配置eth0 提示Device does not seem to be present
查看>>
OS开发入门教程(1)
查看>>
arduino 驱动电调
查看>>
一个游标的性能问题
查看>>
JMeter学习-2 JMeter环境搭建
查看>>
SQL SERVER 2012疑难问题解决方法
查看>>
关于Android RenderScript 的详细说明和一些实用文档
查看>>
POJ1051 P,MTHBGWB
查看>>
士兵队列训练问题
查看>>
js时间戳怎么转成日期格式
查看>>
div宽度设置无效问题解决
查看>>
【ArcGIS Server 开发系列】Flyingis六大系列讲座精品PDF奉献
查看>>