在 REQUIRES_NEW 中更新,然后在不同的事务中查找返回旧数据。为什么?

发布于 2024-08-31 03:21:56 字数 108 浏览 10 评论 0原文

这个问题我觉得用一张图来描述最好。我希望有人能帮助我。谢谢

This question is best described by a picture I think. I hope someone can help me. Thanksalt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单身狗的梦 2024-09-07 03:21:56

我同意 Pascal,如果来自 EJB1 的两个调用位于同一事务中,那么很明显 (2) 无法看到 (1) 执行的更改,因为它们是在另一个事务中执行的(当然,假设合理的事务隔离级别)

1. EJB1 transaction (TX1) starts
2.  EJB1.(1) called
3.   EJB2.update row started => TX1 is suspended and
     a new transaction, TX2, is started
4.   The update is performed
5.   TX2 commits
6.  TX1 is resumed - it can't see changes by TX2 because it's isolated from
    changes performed by other transactions during its "life"
7.  EJB1.(2) invokes EJB2.find row withing the context of TX1 => can't see TX2's changes
8. TX1 commits

I agree with Pascal, if the two calls from EJB1 are in the same transaction then it's clear that (2) cannot see the changes performed by (1) because they were performed in another transaction (assuming a reasonable transaction isolation level, of course)

1. EJB1 transaction (TX1) starts
2.  EJB1.(1) called
3.   EJB2.update row started => TX1 is suspended and
     a new transaction, TX2, is started
4.   The update is performed
5.   TX2 commits
6.  TX1 is resumed - it can't see changes by TX2 because it's isolated from
    changes performed by other transactions during its "life"
7.  EJB1.(2) invokes EJB2.find row withing the context of TX1 => can't see TX2's changes
8. TX1 commits
孤云独去闲 2024-09-07 03:21:56

我不确定您是否提供了所有上下文,但如果 (1) 和 (2) 在同一个事务中运行,我会说该实体位于 L1 缓存中,这就是问题所建议的,并且在“更新行”不可见,因为它们是在另一个持久性上下文(嵌套事务)内完成的,因此需要 从数据库刷新实例的状态。

I'm not sure you gave all the context but if (1) and (2) are running inside the same transaction, I'd say that the entity is in the L1 cache, that's what the question suggests, and that changes made in "update row" are not visible because they were done inside another persistence context (a nested transaction), hence the need to refresh the state of the instance from the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文