Sobes.tech
Senior

How does Spring behave when calling a method of another bean with @Transactional(propagation = REQUIRES_NEW) from a method with default propagation? What happens to the parent transaction?

sobes.tech AI

Answer from AI

When a method annotated with @Transactional(propagation = REQUIRES_NEW) is called from another method with the default propagation (REQUIRED), Spring creates a new, separate transaction for this call. The parent transaction is then suspended during the execution of the method with REQUIRES_NEW.

That is:

  • The parent transaction is suspended.
  • A new transaction is created for the child method.
  • After the child transaction completes (commit or rollback), the parent transaction resumes.

This allows isolating the operations of the child method from the parent transaction, for example, so that changes in the child method are committed independently of the parent transaction's outcome.

How does Spring behave when calling a method of… - sobes.tech