当前位置:网站首页>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.
边栏推荐
猜你喜欢

汉源高科2光12电千兆导轨式网管型工业以太网交换机双光自愈保护式以太网光交换机

一款免费的容器安全 SaaS 平台使用记录

字节内部技术图谱 惊艳级实用

A brief discussion on the transformation of .NET legacy applications
VisualStudio 制作Dynamic Link Library动态链接库文件

汉源高科千兆4光4电工业级网管型智能环网冗余以太网交换机防浪涌防雷导轨式安装

go——垃圾回收机制(GC)
![[c] Detailed explanation of operators (1)](/img/7d/5f2030dcae0f3af16f6e9a37ff041b.png)
[c] Detailed explanation of operators (1)

I interviewed a 985 graduate, and I will never forget the expression when answering the "performance tuning" question
快速构建电脑软件系统 、超好用经典的网页推荐汇总
随机推荐
go——垃圾回收机制(GC)
行业 SaaS 微服务稳定性保障实战
CS5213芯片|HDMI to VGA转换头芯片资料分享
C#异步和多线程
工厂模式理解了没有?
源码构建LAMP环境-3
用户之声 | GBASE南大通用实训有感
Flink优化及相关
性能测试 - 理论
矩阵白化原理及推导
从零开始配置 vim(5)——本地设置与全局设置
Win10怎么开启自带的游戏录屏功能?
【C语言进阶】--指针典题剖析
手把手教你干掉if else
golang刷leetcode:巫师的总力量和
C primer plus学习笔记 —— 9、联合&枚举&typdef
js: 实现一个cached缓存函数计算结果
总结嵌入式C语言难点(2部分)
人尽皆知的云原生,到底是大势所趋还是过度炒作?
Li Mu hands-on learning deep learning V2-bert and code implementation