javaormjpajakarta-eesecond-level-cache

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. Thanksalt text


Solution

  • 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