当前位置:网站首页>[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
边栏推荐
- Call API interface to generate QR code of wechat applet with different colors
- Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
- MySQL Chapter 5 Summary
- CentOS installs redis multi master multi slave cluster
- MySQL 9th job - connection Query & sub query
- How QT uses quazip to compress and decompress files
- Procedure Call Standard
- Leetcode intermediate node of linked list
- [binary search] 4 Find the median of two positive arrays
- Under the double reduction, the amount of online education has plummeted. Share 12 interesting uses of webrtc
猜你喜欢
About multi table query of MySQL
OpenCV图像处理-灰度处理
The fourteenth MySQL operation - e-mall project
36 qtextedit control input multiline text
瑞萨电子面向物联网应用推出完整的智能传感器解决方案
【LeetCode】59. Spiral matrix II
JS reverse | four libraries and one platform response data encryption
The sixth MySQL job - query data - multiple conditions
MySQL第十一作业-视图的应用
AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D
随机推荐
MySQL项目8总结
Global and Chinese market for change and configuration management software 2022-2028: Research Report on technology, participants, trends, market size and share
Appium自动化测试基础 — 移动端测试环境搭建(二)
MySQL第五章总结
【Leetcode】76. Minimum covering substring
118. Yanghui triangle
String constant pool, class constant pool, and runtime constant pool
Allocation of heap memory when creating objects
The sixth MySQL job - query data - multiple conditions
MySQL第六章总结
MySQL 12th job - Application of stored procedure
MySQL第十三次作业-事务管理
What are the symbolic and direct references of the JVM
字符串常量池、class常量池和运行时常量池
量化投资学习——经典书籍介绍
Solution to the problem of compilation error due to repeated third-party package names
创建对象的时候堆内存的分配
String类intern()方法和字符串常量池
About multi table query of MySQL
Enter a positive integer with no more than 5 digits, and output the last digit in reverse order