Propagation

Propagation will help to determine when the query should run in a transaction and what transaction to use.

REQUIRED (default)

In REQUIRED mode, the function will inspect the context for a transaction, use one if exists and create a new one if none exists.

class Service {
    @Transactional(Propagation.REQUIRED)
    async methodA() {
        // methodA will create a transaction.
        
        // methodB will use transaction created by methodA.
        await this.methodB();
    }
    
    @Transactional(Propagation.REQUIRED)
    async methodB() { ... }
}

REQUIRES_NEW

In REQUIRES_NEW mode, the function will always create and use a new transaction and assign it to the subsequent async context, even if one exists in the current context.

MANDATORY

In Mandatory mode, the function will inspect the context for a transaction, if it finds a transaction it will use it, if it does not it will throw an error.

SUPPORTS

In SUPPORTS mode, the function will inspect the context for a transaction, if it finds one it will use it, if not, it will run the queries without a transaction.

NOT_SUPPORTED

In NOT_SUPPORTS mode, the function will always run outside the current context transaction.

NEVER

In NEVER mode, the function will run outside a transaction if non exists in the current context, and will throw an error if a transaction exists in the current context.

Last updated