Search code examples
error-handlingtransactionsrollbackspring-retry

Why are Spring retry's stateful retries necessary with transactional resources?


In Spring retry's README, they mention how a "stateless retry" is not enough to rollback a transaction, but a stateful retry can by using a Map ?

I don't really understand what they mean.

If I want a transactional method to rollback the transaction and retry with a new one, how is a stateful retry different than a stateless retry ?


Solution

  • In order for the transaction to roll back, the exception must be propagated to the caller (assuming the transaction is started somewhere upstream of the retryable method).

    With stateless, the retries are performed within the scope of a single transaction.