@Transactional is a Spring annotation used to manage database transactions automatically. It ensures that a group of database operations executes as a single unit of work. If all operations complete successfully, the transaction is committed; if any operation fails, the entire transaction is rolled back, maintaining data consistency and integrity.
Consider a banking application where money is transferred from one account to another. Both the debit and credit operations must succeed together. If one operation fails, the transaction should roll back to prevent inconsistent account balances.
@Service
public class BankService {
@Transactional
public void transferMoney(
Long fromAccount,
Long toAccount,
double amount) {
debitAccount(
fromAccount,
amount);
creditAccount(
toAccount,
amount);
}
}A concise interview answer is: @Transactional is used to define a transactional boundary in Spring. It ensures that multiple database operations execute as a single unit of work, where all changes are committed if successful or rolled back if an error occurs, thereby maintaining data consistency and integrity.
Last updated: 11 November 2026
Previous question: What is the difference between @Qualifier and @Primary, and when is each used?
Next question: What are Spring profiles, and how do you start an application with a specific profile?