开发者

When to use @Transactional's propagation=Proagation.REQUIRES_NEW?

开发者 https://www.devze.com 2023-03-20 07:06 出处:网络
My question is simple and nearly already stated in the title: Is there a specific pattern/ use-case where one would say that @Transactional(pro开发者_如何学Gopagation=Proagation.REQUIRES_NEW) instead

My question is simple and nearly already stated in the title: Is there a specific pattern/ use-case where one would say that @Transactional(pro开发者_如何学Gopagation=Proagation.REQUIRES_NEW) instead of the default propagation should be used?

Thanks !


Writing an audit trail. You want to record the fact that someone tried to do something irrespective of whether the main transaction succeed or failed (and hence got rolled back).


Specific uses include scenarios where you need to perform some work in a method, and commit it before continuing the existing transaction.

"Auditing" (and not logging) of method invocations, for instance, is a scenario where you would want to commit the audit entry irrespective of whether the existing business transaction will commit or rollback in the end.

Another scenario would be the case where you have several business transactions that are being invoked from a facade, and each such invocation must commit it's work before returning control to the facade. This scenario is quite rare, but you might find this in a workflow system that creates it's own transaction (where entries are recorded on the progress of the workflow), and invocations on other components residing in the same application, must occur in separate transactions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号