大家,
我正在使用 Mysql 学习 springboot,并尝试专注于事务。我通过以下链接获取指导:
https://github.com/spring-guides/gs-managing-transactions/tree/master/complete
当我执行第一笔交易时,Alice、Bob 和 Carol
被保存。
当我执行第二个事务时,Chris 或 Samuel
被丢弃,因为 Samuel 违反了数据库约束。
我现在想知道的是, 1. 当第二个事务失败时,有没有办法回滚第一个事务? 2. 一切完成后保存所有交易...
最佳答案
是的。
您只需将两个事务声明为 2 个不同的方法,并在第一个事务方法中使用 @Transactional (propagation=Propagation.REQUIRED)
对其进行注释。
有关更多详细信息,请研究事务传播:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/Propagation.html .
关于mysql - 当其他事务失败时,Spring Boot事务停止自动提交或回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46325194/