Everone,
I am learning springboot with Mysql and trying to concentrate on Transactions. I am following the below link for guidance :
https://github.com/spring-guides/gs-managing-transactions/tree/master/complete
When i execute the first transaction Alice, Bob and Carol
gets saved.
When i execute the Second transaction Chris or Samuel
gets discarded because Samuel has violated DB constraints.
All i want to know now is, 1. Is there a way to rollback the first Transaction when second Transaction Fails ? 2. Save all transaction when everything is completed...
Yes.
You just have to declare both transactions into 2 different methods and annotate them with @Transactional (propagation=Propagation.REQUIRED)
from the first transaction method.
For more details study transaction propagation : https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/Propagation.html .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.