What is the @Transactional
Annotation?
The @Transactional
annotation in Spring Framework is used for transaction management. It ensures that database operations (CRUD - Create, Read, Update, Delete) are executed safely.
📌 How Does @Transactional
Work?
When you use @Transactional
in Spring, it creates a transactional block. If all operations inside the block are successful, the database commits the changes. However, if any error (exception) occurs, the entire transaction rolls back, meaning the database returns to its previous state.
Why we don't use @Transactional annotation for creating data repository?
@Transactional annotation. All the methods of SimpleJpaRepository are by default transactional. Therefore if we extend JpaRepository in our repository class then no need to add @Transactional annotation at methods of the repository.
Comments
Post a Comment