gpt4 book ai didi

java - 在 Spring 中使用哪种传播?

转载 作者:搜寻专家 更新时间:2023-10-31 19:37:52 24 4
gpt4 key购买 nike

我有两个不同的进程(A 和 B),A 必须在 B 之后开始,B 不能加入 A 的事务,B 必须等到 A 完成提交。

我应该使用什么传播方式?

现在是这样的:

@Transactional
A()

@Transactional
B()

现在我默认使用它@Transactional,但它不能正常工作。我想我应该使用PROPAGATION

我希望问题很清楚。提前致谢。

最佳答案

如果 B() 在其事务上下文中调用 A(),则 A() 应该使用 REQUIRES_NEW 传播到有自己独立的交易。 enter image description here

根据spring框架的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.

关于java - 在 Spring 中使用哪种传播?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32377266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com