Junior — Middle
How does Spring manage nested transactions within a single component or method?
sobes.tech AI
Answer from AI
Spring supports nested transactions using the NESTED propagation type. When this type is used within an existing transaction, a savepoint is created. If the nested transaction is rolled back, only to this savepoint, and the outer transaction can continue. It is important that support for savepoints at the data source level (e.g., JDBC) is available for nested transactions to work. Example annotation:
@Transactional(propagation = Propagation.NESTED)
public void nestedTransactionMethod() {
// method code
}
If nested transactions are not used, the default is REQUIRED, which simply joins the existing transaction.