I am new at learning spring boot. I want to know what are the real-world use-cases of REQUIRES_NEW in propagation attribute of @Transactional annotation.
I am aware that it suspends the ongoing transaction if the request for the new Transaction arrives and then resumes after completing the newly requested transaction.
I think Understanding transaction pitfalls article explains it in a nice way:
the REQUIRES_NEW transaction attribute should be used only if the database action in the method being invoked needs to be saved to the database regardless of the outcome of the overlaying transaction. For example, suppose that every stock trade that was attempted had to be recorded in an audit database. This information needs to be persisted whether or not the trade failed because of validation errors, insufficient funds, or some other reason. If you did not use the REQUIRES_NEW attribute on the audit method, the audit record would be rolled back along with the attempted trade. Using the REQUIRES_NEW attribute guarantees that the audit data is saved regardless of the initial transaction's outcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With