当前位置:网站首页>[difficult and miscellaneous diseases] @transitional failure summary
[difficult and miscellaneous diseases] @transitional failure summary
2022-06-26 10:41:00 【My name is 985】
In daily development , I met a very difficult problem ! The transaction does not take effect ! The pseudocode is shown below
public interface PersonService{
public batchAddPerson();
}
@Service("personService")
puiblic class PersonServiceImpl implements PersonService {
@Transational // If comments are normal here
@Override
public batchAddPerson(List<PersonBo> personList){
for(PersonBo person : personList){
this.addPerson(person );
}
}
// If @Transational Note: it is found that no transaction is opened here , So there is no rollback ;
// If so batchAddPerson and addPerson If you add business , that addPerson There are open transactions
@Transational
public void addPerson(){
dao.addPerson();
throw new RuntimeException();
}
}
By looking up relevant information , Summarize the following situations that can lead to @Transational invalid
1. In the same class , One nan-transactional To call transactional Methods , The transaction will fail
@Transational Separate notes in addPerson The reason for the invalid method is :addPerson Be being batchAddPerson Called , and batchAddPerson There is no transaction open .
@Transational Separate notes in batchAddPerson The reason for the entry into force is :batchAddPerson Started the business , and batchAddPerson Called addPerson, The default transaction propagation behavior is if the sub method does not start the transaction , Create a new transaction for the sub method
@Transational Annotations in batchAddPerson、addPerson The reason why the two methods work : They all started the business .( doubt : But I don't know addPerson Will there be a new transaction )
[email protected] By default, only those deriving from RuntimeException perhaps Error It's abnormal
@Transational By default, only those deriving from RuntimeException perhaps Error It's abnormal , Only when these exceptions are found will the rollback be performed . If the business throws out Exception The latter custom exception , Need to pass through @Transational Of rollbackFor Property must be specified to take effect
3. stay private Label on method transactional, Invalid transaction
@Transational Can only be marked on public On
Reference blog :https://www.cnblogs.com/milton/p/6046699.html
边栏推荐
- Under the double reduction, the amount of online education has plummeted. Share 12 interesting uses of webrtc
- Enter a positive integer with no more than 5 digits, and output the last digit in reverse order
- MySQL第八次作业
- String class intern() method and string constant pool
- Global and Chinese market of amateur football helmets 2022-2028: Research Report on technology, participants, trends, market size and share
- SSH, SCP command appears permission denied, please try again solution
- US President signs community safety act to deal with gun issue
- 瑞萨电子面向物联网应用推出完整的智能传感器解决方案
- Search engine advanced search method records
- 工程数学概率论统计简明教程第二版复习大纲
猜你喜欢

Développeur, quelle est l'architecture des microservices?

SwiftUI 开发经验之为离线优先的应用程序设计数据层

首批12家企业入驻!广州首个集中展销老字号产品专柜开张

904. fruit baskets

3行3列整形二维数组,求对角之和

The sixth MySQL job - query data - multiple conditions

Basic string operations in C

Flutter and native communication (Part 1)

Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data

Appium自动化测试基础 — 移动端测试环境搭建(二)
随机推荐
echo $?
String constant pool, class constant pool, and runtime constant pool
MySQL seventh job - update data
【無標題】
Cmake / set command
Idea remote debugger
String constant pool, class constant pool, and runtime constant pool
Use of exec series functions (EXECL, execlp, execle, execv, execvp)
Call API interface to generate QR code of wechat applet with different colors
Installer MySQL sous Linux [détails]
Flutter and native communication (Part 1)
MySQL第七次作业-更新数据
[online simulation] Arduino uno PWM controls the speed of DC motor
開發者,微服務架構到底是什麼?
Global and Chinese market of cryogenic bulk tanks 2022-2028: Research Report on technology, participants, trends, market size and share
The first batch of 12 enterprises settled in! Opening of the first time-honored product counter in Guangzhou
Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
appliedzkp zkevm(8)中的Plookup Table
String class intern() method and string constant pool
量化投资学习——经典书籍介绍