[jboss-jira] [JBoss JIRA] Commented: (EJBTHREE-1072) Ejb3TxPolicy does not rollback the transaction in case of an error
Alexey Loubyansky (JIRA)
jira-events at lists.jboss.org
Mon Mar 10 12:35:58 EDT 2008
[ http://jira.jboss.com/jira/browse/EJBTHREE-1072?page=comments#action_12401988 ]
Alexey Loubyansky commented on EJBTHREE-1072:
---------------------------------------------
I don't see this happening with the current trunk. I wrote a testcase that shows that the transaction is properly rolledback. It's added to
package org.jboss.ejb3.test.txexceptions.unit;
public class TxExceptionsTestCase extends JBossTestCase
public void testRollbackError() throws Exception
I also tried adding the following logging to the method that persists the entity:
SimpleEntity entity = new SimpleEntity();
entity.setId(id);
entity.setStuff("stuff");
manager.persist(entity);
try
{// get current transaction and log its status
Transaction tx = org.jboss.tm.TransactionManagerLocator.locateTransactionManager().getTransaction();
System.out.println("current tx: " + tx);
System.out.println("current tx status: " + org.jboss.tm.TxUtils.getStatusAsString(tx.getStatus()));
// register synchronization and log the status of the tx in afterCompletion
tx.registerSynchronization(new javax.transaction.Synchronization(){
public void afterCompletion(int arg0)
{
System.out.println("afterCompletion: " + org.jboss.tm.TxUtils.getStatusAsString(arg0));
}
public void beforeCompletion()
{
}});
}
catch (Exception e)
{
e.printStackTrace();
}
}
After this code is called, the Error is thrown. In the logs I can see that the transaction was active when persist was called and its status was "rolled back" in afterCompletion. And the entity could not be found in the database.
I guess, the Error is wrapped into RuntimeException in InvocationContextImpl and Ejb3TxPolicy shouldn't be changed. I'll check it after updating my environment.
> Ejb3TxPolicy does not rollback the transaction in case of an error
> ------------------------------------------------------------------
>
> Key: EJBTHREE-1072
> URL: http://jira.jboss.com/jira/browse/EJBTHREE-1072
> Project: EJB 3.0
> Issue Type: Bug
> Affects Versions: AS 5.0.0.Beta3
> Reporter: Olaf Fricke
> Assigned To: Alexey Loubyansky
> Priority: Critical
> Fix For: AS 5.0.0.CR1
>
>
> The class Ejb3TxPolicy is used to rollback the transaction in the case of exceptions. According to the ejb 3.0 spec, the transaction is rolled back in case of ApplicationException with rollback() evaluating to true, in case of RuntimeExceptions or in case of EjbException.
> All other exception will not lead to a rollback on the current transaction.
> Unfortunately, the same is true in case of errors. If, for example, an AssertionError (or a ClassDefNotFoundError etc.) occurs, the current transaction will be committed and not rolled back. This behaviour is wrong with respect to the ejb 3.0 spec (see for example table 14 on page 360 of ejbcore.pdf)
> A possible solution would be to wrap the error into a new RuntimeException after handling ApplicationException (in both methods handleExceptionInOurTx and handleInCallerTx):
> <code>
> if (t instanceof Error)
> {
> t = new RuntimeException(t);
> }
> if (!(t instanceof RuntimeException || t instanceof RemoteException))
> {
> throw t;
> }
> </code>
> The wrapping is necessary, because both the EJBException and the EJBTransactionRolledbackException can only handle exceptions, but not errors.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list