当前位置:网站首页>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.
边栏推荐
猜你喜欢
ECCV 2022 | ByteTrack: 简单高效的数据关联方法
go——内存分配机制
汉源高科千兆4光4电工业级网管型智能环网冗余以太网交换机防浪涌防雷导轨式安装
The software testing process specification is what?Specific what to do?
A brief discussion on the transformation of .NET legacy applications
命令行启动常见问题及解决方案
面试了个985毕业的,回答“性能调优”题时表情令我毕生难忘
Jar包启动通过ClassPathResource获取不到文件路径问题
How to quickly compare two byte arrays for equality in .NET
2022年金九银十,Android面试中高频必问的问题汇总
随机推荐
golang刷leetcode:按位与结果大于零的最长组合
包管理工具npm- node package management相关知识 、检查包更新、NPM包上传、更换镜像、npm ERR! registry error parsing json
如何成为一名正义黑客?你应该学习什么?
golang刷letcode:公平分发饼干
博客主页rrs代码
Electrical diagram of power supply system
行业 SaaS 微服务稳定性保障实战
Mysql用户管理
golang刷letcode:公司命名
源码构建LAMP环境-2
win10安全中心设置不扫描某个文件夹的方法
《分布式微服务电商》专题(一)-项目简介
解道8-编程技术5
总结嵌入式C语言难点(2部分)
[C题目]力扣142. 环形链表 II
How to use windbg check c # a thread stack size?
golang刷leetcode: 小于等于 K 的最长二进制子序列
Nervegrowold hands-on learning deep learning V2 - Bert pre training data set and code implementation
【目标检测】YOLOv5:640与1280分辨率效果对比
56.【全局变量和局部变量专题】