Introduction
In Spring Boot, @Transactional is one of the most used annotations as it is used to manage transactions and used to define a scope of transaction. It can either be applied to the method level or class level. It provides data consistency and reliability.
Understanding transaction management in Spring Boot using @Transactional
• @Transactional annotation simplifies transaction management by providing a more declarative approach.
• This annotation can be used at the method level or class level.
• Developers can focus more on the business logic aspect and the annotation takes care of the transaction management.
• Transactional annotation is used for managing transactions in the spring-boot application.
Why Do We Need Transaction Management?
Let’s grasp the concept of transactions through the provided example, considering we are having 2 tables, offer_criteria and offer when saving offer data into the database, it is crucial to save to save both information to the database.
Attributes of @Transaction
• Propogation — defines our business logic’s transaction boundary. Spring boot manages to start and pause a transaction according to the propagation setting set.
• Isolation- represents how changes applied by concurrent transactions are visible to each other. Each isolation level prevents zero or more concurrency side effects on a transaction.
• ReadOnly- marks the transaction as read only.
• TimeOut- sets the time limit for the transaction.
• RollbackFor & NoRollbackFor — Specify exceptions that trigger a rollback or do not trigger a rollback, respectively.
Hope this article has given you more understanding about @transactional annotation and the importance of using it when dealing with more than one database call in single transaction.
Thanks for reading, kindly give like and follow for more articles.