Spring Boot Transaction Management
How Spring Boot Transaction Management Works with the @Transactional annotation and Propagation types.
The process of combining related operations into single unit and executing them by applying do everything or nothing principle is called Transaction Management.
We execute sensitive logics like ticket booking, transfer money and etc. logics by enabling transaction management support.
TRANSACTION PROPAGATION TYPE :
1. REQUIRED
2. SUPPORTS
3. MANDATORY
4. REQUIRES_NEW
5. NOT_SUPPORTED
6. NEVER
7. NESTED
1. REQUIRED :
========
- If the addMessage() is called directly then it will create its own Transaction.
- If the add message is called from another service –
a. If the calling MessageService method has a transaction then method make use of the existing transaction.
b. If the calling MessageService method does not have any transaction then the method will create new transaction.
So in case of REQUIRED the addMessage() method makes use of the calling UserService method transaction if it exists else create its own.