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
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.
发布评论
评论(2)
我同意 Pascal,如果来自 EJB1 的两个调用位于同一事务中,那么很明显 (2) 无法看到 (1) 执行的更改,因为它们是在另一个事务中执行的(当然,假设合理的事务隔离级别)
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) 和 (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.