当前位置:网站首页>@Several scenarios of transactional failure
@Several scenarios of transactional failure
2022-06-28 04:04:00 【Cloud on cloud】
Spring Of @Transactional Annotations control which scenarios the transaction does not take effect ?
1. The database engine does not support transactions ( only InnoDB Support )
from MySQL 5.5.5 The default storage engine to start with is :InnoDB, Before the default is :MyISAM, So it's worth noting , The underlying engine doesn't support transactions. No matter what happens, it's just a waste of time .
[email protected]Transactional Annotations can only be applied to public The method of visibility
If it is to be used in non public On the way , Can be opened AspectJ The proxy pattern .
The following is from Spring Official documents :
When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.
3..try-catch abnormal , The transaction will not take effect
It's also the most common , Eat the abnormal , And then don't throw it out , The transaction will not roll back !
spring The transaction of is started before calling the business method , The business method is executed after execution commit or rollback,
Whether a transaction is executed depends on whether it is thrown runtime abnormal . If you throw runtime exception And there's no... In your business approach catch When you arrive , The transaction rolls back .
This situation can be used @Transactional(rollbackFor = Exception.class) Processing or reprocessing catch Manually execute rollback in

4. By default ,Spring Would be right Error perhaps RuntimeException Abnormal transaction rollback ,
Others inherit from java.lang.Exception It's abnormal : Such as IOException、TimeoutException etc. , No rollback .
Solution :Transactional Annotation plus rollbackFor attribute , Appoint java.lang.Exception.class;
5. Method calls in the same class , Lead to @Transactional invalid
scene : In development, it is inevitable to call methods in the same class , For example, there is a class Test, One way of it A,A Call the methods of this class B
( No matter how B Yes, it is public still private modification ), But the way A There is no declaration to annotate the transaction , and B There are methods . Then the external call method A after ,
Method B It doesn't work .
reason : Due to the use Spring AOP The agent caused , Because only when the transaction method is called by code other than the current class , Only by Spring Generated proxy objects to manage .
边栏推荐
- 02 MongoDB数据类型、重要概念以及shell常用指令
- Several important physical concepts
- MySQL 主从复制、分离解析
- 谈云原生,不得不谈的容器
- Meichuang was selected into the list of "2022 CCIA top 50 Chinese network security competitiveness"
- 组件拆分实战
- MSC 307(88) (2010 FTPC Code) Part 9床上用品试验
- 基于正点原子stm32的mini板的TFTLCD显示实验
- 数字有为,易步到位 华为携“5极”明星产品加速布局商业市场
- Building log analysis system with elk (II) -- deployment and installation
猜你喜欢

一文告诉你什么是 Kubernetes

AS 3744.1标准中提及ISO8191测试,两者测试一样吗?

Cannot edit in read-only editor if it appears in vscode

The operating mechanism of spectrogram in audio Science

How to write a software test report? Here comes the third party performance report template

leetcode:单调栈结构(进阶)

Door level modeling - learning notes

视频爆炸时代,谁在支撑视频生态网高速运行?

用Pycharm开发Flask框架设置debug模式没有效果的解决办法

vscode中出现无法在只读编辑器中编辑
随机推荐
Several important physical concepts
解析教育机器人的综合应用能力
Analysis of future teacher research ability under steam education framework
揭开SSL的神秘面纱,了解如何用SSL保护数据
谈云原生,不得不谈的容器
多项目设计开发·类库项目引入入门
applicationContext. Getbeansoftype obtains the execution methods of all implementation classes under an interface or obtains the operation application scenarios such as implementation class objects. L
多线程与高并发三:AQS底层源码分析及其实现类
C语言十进制与BCD码的相互转换
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
vscode中出现无法在只读编辑器中编辑
Pointer linked list
2022年6月对自己近况的一次总结
English grammar_ Adjective / adverb Level 3 - Comparative_ Useful Expressions
从零到一,教你搭建「以文搜图」搜索服务(一)
机器人编程教育的市场竞争力
利用ELK 搭建日志分析系统(三)—— 安全认证
One article tells you what kubernetes is
窗帘做EN 1101易燃性测试过程是怎么样的?
ELK 搭建日志分析系统 + Zipkin服务链路追踪整合