Transaction Propagation Types in Spring

In this article, we will understand the different transaction propagation types available in Spring Boot.


Why do we call this Transaction Propagation?

When we call a method from another method then we might want to propagate the existing transaction context or restrict the propagation & create a new context. Hence we call this as transaction propogation.
We use @Transactional annotation of Spring to wrap a method inside a database transaction context.

So, using this @Transactional annotation, we can set our desired propagation type.

This annotation provides us the ability to decide : whether we want to use an existing active transaction or we want to create a new transaction.

The new transaction can be a fresh one (not within any another transaction) or it can be a nested transaction inside an existing active transaction.

By transaction, we mean a transactional context here. So, either we can use an existing context or can start a new context altogether.

There can be multiple use cases when we are calling the method like: we want to use existing/new context or we do not want any context at all etc. Based on these use cases, we have 7 types of propagations available:

  1. Propagation.REQUIRED
  2. Propagation.SUPPORTS
  3. Propagation.MANDATORY
  4. Propagation.NEVER
  5. Propagation.NOT_SUPPORTED
  6. Propagation.REQUIRES_NEW
  7. Propagation.NESTED

Leave a Comment