博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
23. Spring 事务注解@Transactional和异常捕获
阅读量:7144 次
发布时间:2019-06-29

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

一. 事务注解限制条件

1. 不允许在private方法上面

2. 不能在非事务方法里面调用事务方法

二. 实现机制-异常捕获

1
2
3
4
5
6
Describes transaction attributes on a method or class.
This annotation type is generally directly comparable to Spring's org.springframework.transaction.interceptor.RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction 
support code does not have to know about annotations. If no rules are relevant 
to the exception, it will be treated like org.springframework.transaction.interceptor.DefaultTransactionAttribute (rolling back on RuntimeException and Error but not on checked exceptions).
For specific information about the semantics of this annotation's attributes, 
consult the org.springframework.transaction.TransactionDefinition and org.springframework.transaction.interceptor.TransactionAttribute javadocs.

所以如果操作数据库的时候把异常捕获了,那么将不能回滚。

三. 手动回滚

1
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

所以为了解决这种矛盾,可以捕获异常后,在catch里面手动调用回滚。

     本文转自rongwei84n 51CTO博客,原文链接:http://blog.51cto.com/483181/1937481,如需转载请自行联系原作者
你可能感兴趣的文章
TCP/IP详解学习笔记(2)-数据链路层
查看>>
VMware+Windgb+Win7内核驱动调试
查看>>
initWithFrame、initWithCoder、awakeFromNib的区别和调用次序 & UIViewController生命周期 查缺补漏...
查看>>
客户端请求新页面
查看>>
VMware安装CentOS时,无法以图形界面安装解决办法
查看>>
SpringMvc文件资源防止被外链链接
查看>>
Spring 4 官方文档学习(十一)Web MVC 框架
查看>>
使用 Spring Boot 快速构建 Spring 框架应用--转
查看>>
Quartz 2D
查看>>
Eclipse 快捷键
查看>>
VC++ 设置软件开机自启动的方法
查看>>
MyBatis学习(三)、动态SQL语句
查看>>
PLSQL:[1]plsql中文乱码,显示问号
查看>>
将十进制转成十六进制
查看>>
【题目】英文字符进行频率的统计,直方图输出
查看>>
Ztree手风琴效果(第三版)
查看>>
「坐上时光机,查找编译压缩后的文件最初的样子」gulp-sourcemaps 使用说明
查看>>
java 泛型中 T、E ... 和 问号(通配符)的区别
查看>>
MyEclipse使用总结——MyEclipse去除网上复制下来的来代码带有的行号
查看>>
java service wrapper日志参数设置及优化
查看>>