Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you use JTA transactions than the transaction boundary spreads from method's begin to its end. </p> <p>Therefore, changes made in an <strong>active</strong> transaction T1 can't be seen in transaction T2. If you think about it, it's quite reasonable. Assume that T2 could operate on data which was changed by T1 but <strong>not committed</strong>. Upon T1 rollback, every changes made to the entities in T1 must be invalidated. You've ended in a situation in which T2 operated on invalid data.</p> <p>That's why you won't see 'Joe 1' (this value is changed only in T1) from any transaction other than T1. You can only see 'Joe 2' when methods ends (T1 commits).</p> <p>The <a href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#flush%28%29" rel="nofollow">EntityManager#flush()</a> synchronizes the data with the underlying database but <strong>does not commit it</strong>. For more detailed information you can see this thread: <a href="http://www.java.net/node/665442#comment-678155" rel="nofollow">http://www.java.net/node/665442#comment-678155</a></p> <p>I can see three solutions in this case:</p> <ol> <li><p>Optimistic locking could save you from situations in which two transactions T1 and T2 change the same data (the same entity). In case you have no locking, only the last committed transaction changes will be reflected in the database (so you've changes made by the former transaction are lost). With locking, you will get an Exception in the last committed transaction, so no data will be lost.</p></li> <li><p>Pessimistic locking could lock the data for the time of modification. In this case, your transaction T2 would not operate on the data until T1 finishes.</p></li> <li><p>At last - the most simple situation is (if possible) just to separate your method to smaller chunks.</p></li> </ol> <p>HTH.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload