当前位置:网站首页>Summary of @Transactional transaction invocation and effective scenarios
Summary of @Transactional transaction invocation and effective scenarios
2022-08-03 00:10:00 【Floating life like a dream】
1. In the same class, transaction publicA drops non-transaction B, B throws an exception, and AB transaction takes effect (with propagation)
@[email protected] void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);B();}public void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);// trigger exceptionif(3/0==1)System.out.println("");}
2. In the same class, transaction A drops non-transaction B, A throws an exception, and AB transaction takes effect
@[email protected] void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);B();// trigger exceptionif(3/0==1)System.out.println("");}public void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);}
3. In the same class, transaction A drops transaction B, A throws an exception, and AB transaction takes effect
@[email protected] void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);B();// trigger exceptionif(3/0==1)System.out.println("");}@Transactionalpublic void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);}
4. In the same class, transaction A drops transaction B, B throws an exception, and AB transaction takes effect
@[email protected] void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);B();}@Transactionalpublic void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);// trigger exceptionif(3/0==1)System.out.println("");}
5. In the same class, non-transaction A drops transaction B, B throws an exception, A has no transaction, and B transaction does not take effect
@Overridepublic void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);B();}@Transactionalpublic void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);// trigger exceptionif(3/0==1)System.out.println("");}
6. In the same class, non-transaction A drops transaction B (through injection - equivalent to calling B method in different classes) B throws exception A has no transaction, B transaction takes effect
@Overridepublic void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);userService.B();}@[email protected] void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);// trigger exceptionif(3/0==1)System.out.println("");}
7. In the same class, non-transaction A drops transaction B (through injection), A throws exception, A has no transaction, B does not trigger transaction, and ab data will increase success
@Overridepublic void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);userService.B();// trigger exceptionif(3/0==1)System.out.println("");}@[email protected] void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);}
8. In the same class, transaction A drops non-transaction B (through injection) A or B throws an exception, AB transaction takes effect (transaction propagation)
@[email protected] void A() {User u = new User();u.setAccount("test");u.setName("1");u.setMobile("12345678912");u.setPassword("111");this.save(u);userService.B();// trigger exceptionif(3/0==1)System.out.println("");}@Overridepublic void B() {User u1 = new User();u1.setAccount("test1");u1.setName("2");u1.setMobile("12345678913");u1.setPassword("111");this.save(u1);}
Summary: 1. Transaction A drops B, AB has transactions (transaction propagation) 2. Non-transaction A drops transaction B, A has no transaction, B is only called by injection (AOP), B's transactionto take effect.3. Private cannot add transactions 4. If declarative transactions need to be refined, they can be split.
边栏推荐
- golang刷leetcode: 小于等于 K 的最长二进制子序列
- ECCV 2022 | ByteTrack: 简单高效的数据关联方法
- .NET performance optimization - you should set initial size for collection types
- Bena's life cycle
- X 2 Earn必须依靠旁氏启动?GameFi的出路在哪?(下)
- golang 刷leetcode:将字符串翻转到单调递增
- Zabbix 5.0 Monitoring Tutorial (2)
- Win10怎么开启自带的游戏录屏功能?
- 引用类型 ,值类型 ,小坑。
- 你我都会遇到的需求:如何导出MySQL中的数据~ 简单!实用!
猜你喜欢
Packages and packages, access modifiers
面试官:可以谈谈乐观锁和悲观锁吗
Vscode快速入门、 插件安装、插件位置、修改vscode默认引用插件的路径、在命令行总配置code、快捷键
Li Mu hands-on deep learning V2-BERT pre-training and code implementation
面试了个985毕业的,回答“性能调优”题时表情令我毕生难忘
UDP(用户数据报协议)
How to quickly compare two byte arrays for equality in .NET
【C语言进阶】--指针典题剖析
sre成长之路
Flutter 常见异常分析
随机推荐
Zabbix 5.0 监控教程(二)
golang刷leetcode:道路的最大总重要性
JumpServer开源堡垒机完成龙芯架构兼容性认证
Byte's internal technical map is amazing and practical
树形结构构造示例代码
快速构建电脑软件系统 、超好用经典的网页推荐汇总
golang 刷leetcode:祖玛游戏
解道6-编程技术3
[C题目]力扣141. 环形链表
快速学会ansible的安装
【模型压缩】实例分析量化原理
UDP(用户数据报协议)
golang 刷leetcode:将字符串翻转到单调递增
Electrical diagram of power supply system
2022年金九银十,Android面试中高频必问的问题汇总
@Transactional 事务调用与生效场景总结
Jar包启动通过ClassPathResource获取不到文件路径问题
win10桌面图标全部变成白色的怎么办
vscode如何能将输出从OUTPUT改为TERMINAL或者DebugConsole
.NET performance optimization - you should set initial size for collection types