5
votes

I have two different process ( A and B), and A has to start after B, B must not join the A's transaction, B has to wait until A finish its commit.

what propagation should i use ?

Now it is like :

@Transactional
A()

and

@Transactional
B()

Now i use it defult @Transactional, and its not work properly. I think i should use PROPAGATION.

I hope the question is clear. Thanks in advance.

2

2 Answers

5
votes

If B() in its transactional context calling A(), then A() should use REQUIRES_NEW propagation to has its own independent transaction. enter image description here

According to spring framework's Data Access Section:

PROPAGATION_REQUIRES_NEW, in contrast to PROPAGATION_REQUIRED, uses a completely independent transaction for each affected transaction scope. In that case, the underlying physical transactions are different and hence can commit or roll back independently, with an outer transaction not affected by an inner transaction’s rollback status.

3
votes

enter image description here

This photo pretty much tells you why you should use REQUIRES_NEW. What you want is invocation always occurs in a new transaction(TX) context.

Note however: Actual transaction suspension will not work on out-of-box on all transaction managers. If you are using JtaTransactionManager, you need javax.transaction.TransactionManager to be made available to it.