What is the use of the @Transactional annotation in Spring?

What is the use of the @Transactional annotation in Spring?

A) To define the boundaries of a transaction
B) To configure a database connection
C) To schedule tasks
D) To create REST endpoints

Answer:

A) To define the boundaries of a transaction

Explanation:

The @Transactional annotation in Spring is used to define the boundaries of a transaction. When applied to a method or class, it ensures that the method execution is wrapped in a transaction, meaning that if any part of the method fails, the entire transaction can be rolled back to maintain data consistency.

This annotation can be configured to specify the transaction propagation behavior, isolation level, and other transaction management details. It is commonly used in service layer methods that interact with a database, ensuring that operations such as updates, deletions, or insertions are handled within a transactional context.

Reference links:

https://www.javaguides.net/p/spring-tutorial-beginners-to-expert.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top