<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=dbanduri" rel="nofollow">Deep Banduri</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4184?redirect=false" rel="nofollow">SPR-4184</a></strong> and commented</p>
<p dir="auto">We are seeing an issue that happens with Jboss 4.2.x where a transaction is not rolling back when the time out period has elapsed.</p>
<p dir="auto">Following is the scenario and how I can consistently reproduce the error.<br>
  <br>
We have a transactional method on a bean with 2 db update operations - 1 insert and 1 delete as follows:<br>
  <br>
   public void foo() {<br>
  <br>
               dbInsertOperation();<br>
              <br>
               dbDeleteOperation();<br>
  <br>
   }<br>
  <br>
   I used a very small transaction time of 2 seconds, and then waited on a break point on the dbDeleteOperation line to ensure that the time out period elapses, and then executed the delete operation. What we found is that in 4.2.1, while waiting at the breakpoint, after the time out is detected by JBoss, the database receives a Rollback command from the app server which rolls back the inserted records - and the method still has not completed yet. When I then execute the delete operation, it is executed by SQL Server as a standalone transaction, since the original one associated with the method is already rolled back. When the method now returns, Spring code tries to commit the transaction, gets an IllegalStateException exception, and then tries to rollback and gets another exception. So what we have is the inserted records were rolled back but the deleted records were commited resulting in an inconsistent database.<br>
  <br>
   However this same exact sequence of events in 4.0.3 works exactly as one would logically expect - even after I sit on the breakpoint for a while for the time out period to elapse, then execute the delete statement, it is still part of the transaction associated with the method call. AFter the method call, Spring code tries to commit, gets an exception (I think a RollbackException), and then issues a rollback which is sent to the database and the entire transaction (insert and delete) is rolled back.<br>
  <br>
   So it seems that what was working logically in 4.0.3 seems to be broken in 4.2.x, everything else being equal. Question is why is JBoss issuing a rollback in the middle of the method? I opened a support ticket with JBoss Support - their response is that this is something Spring should be fixing. See below for their response:</p>
<hr>
<p dir="auto">I believe this is a problem with Spring. It should be checking the thread-to-transaction association of the thread doing the delete. In the case of the timeout, it will find that there is an inactive transaction associated with the thread (the transaction has rolled back, but it has not been removed from the active thread). It should not be trying to make forward progress with the thread at that point, particularly if the thread is about to try to do something within the scope of that transaction.</p>
<p dir="auto">The reason this worked in the 4.0.3 release was that the transaction was not rolled back, so the delete operation was done in the scope of the transaction, even though by that point the state of the transaction would have been marked as ROLLBACK_ONLY, i.e., the delete was wasted effort, so it's arguable that Spring should have checked the state anyway and optimised that operation away, since it wasn't going to complete.</p>
<p dir="auto">JBossTS now terminates transactions as soon as their timeout goes off. The old JBossTM did not: it simply marked them as ROLLBACK_ONLY, which will force them to rollback only when the container eventually tries to commit the transaction.<br>
                                     </p>
<hr>
<p dir="auto">Thanks,<br>
Deep</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.6</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398082647" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8786" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8786/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8786">#8786</a> Transaction Manager issue "NO Active JTA Transaction". Sprying trying to synchronise a transaction marked for rollback.</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=kavipriya" rel="nofollow">Kavipriya Gnanasambandam</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4107?redirect=false" rel="nofollow">SPR-4107</a></strong> and commented</p>
<p dir="auto">I am using Spring 2.0.2 with JBoss 4.2.1 which uses Arjuna Transaction Manager. When i am trying to rollback a transaction i am getting the error message as IllegalStateException"No Active JTA Transaction" The integration between Spring and JBOSS does not work properly anymore after upgrading jboss from 4.0.4 to 4.2.1.</p>
<p dir="auto">Raised the same issue in the JBoss forum but they have replied that it is a spring bug that it is trying to synchronise a inactive transaction.</p>
<p dir="auto">For more information Please refer the below links.</p>
<p dir="auto"><a href="http://jira.jboss.com/jira/browse/JBAS-4972" rel="nofollow">http://jira.jboss.com/jira/browse/JBAS-4972</a><br>
<a href="http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;t=118261" rel="nofollow">http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;t=118261</a></p>
<p dir="auto">I have also raised it in the spring forum Please refer the below link</p>
<p dir="auto"><a href="http://forum.springframework.org/showthread.php?t=27867" rel="nofollow">http://forum.springframework.org/showthread.php?t=27867</a></p>
<p dir="auto">Can you please help me out in this as this seems to be very critical.</p>
<p dir="auto">Thanks,<br>
Kavipriya</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.2, 2.5 RC1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398083237" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8862" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8862/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8862">#8862</a> Transaction not rolling back with JBoss 4.2.x</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398082760" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8801" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8801/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8801">#8801</a> Propagation REQUIRES_NEW fails on JBoss Application Server 4.2.1 when keeping a JDBC Connection handle</li>
</ul>
<p dir="auto"><strong>Backported to:</strong> <a href="https://github.com/spring-projects/spring-framework/milestone/45?closed=1">2.0.8</a></p>