开发者

Updating in a REQUIRES_NEW then finding in a different transaction returns old data. Why?

This question is best described by a picture I think. I hope someone can help me. Th开发者_C百科anks

Updating in a REQUIRES_NEW then finding in a different transaction returns old data. Why?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜