Spring事务中requires_new和嵌套传播之间的差异 [英] Differences between requires_new and nested propagation in Spring transactions

查看:392
本文介绍了Spring事务中requires_new和嵌套传播之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 PROPAGATION_REQUIRES_NEW PROPAGATION_NESTED 传播政策之间的行为差​​异。在我看来,在这两种情况下,当前进程都是回滚的,而不是整个事务。任何线索?

I can't understand the behavior difference between the PROPAGATION_REQUIRES_NEW and PROPAGATION_NESTED propagation policies. It seems to me that in both cases, the current process is rollbacked but not the whole transaction. Any clue?

推荐答案

请看这个链接: PROPAGATION_NESTED与PROPAGATION_REQUIRES_NEW? Juergen Hoeller解释得很清楚

See this link: PROPAGATION_NESTED versus PROPAGATION_REQUIRES_NEW? Juergen Hoeller explain it very well


PROPAGATION_REQUIRES_NEW开始新的,给定范围的独立内部交易
。此事务将提交或回滚
完全独立于外部事务,具有自己的
隔离范围,自己的锁定集等。外部事务将在
开始时被暂停内部的一个,并在
内部完成后恢复。 ...

PROPAGATION_REQUIRES_NEW starts a new, independent "inner" transaction for the given scope. This transaction will be committed or rolled back completely independent from the outer transaction, having its own isolation scope, its own set of locks, etc. The outer transaction will get suspended at the beginning of the inner one, and resumed once the inner one has completed. ...

另一方面,PROPAGATION_NESTED启动嵌套事务,
这是现有事务的真正子事务。将发生什么
是在嵌套的
事务开始时将采取保存点。如果嵌套事务失败,我们将回滚到保证点
。嵌套事务是外部
事务的一部分,因此它只会在外部
事务的末尾提交。 ...

PROPAGATION_NESTED on the other hand starts a "nested" transaction, which is a true subtransaction of the existing one. What will happen is that a savepoint will be taken at the start of the nested transaction. Íf the nested transaction fails, we will roll back to that savepoint. The nested transaction is part of of the outer transaction, so it will only be committed at the end of of the outer transaction. ...

这篇关于Spring事务中requires_new和嵌套传播之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆