Transactions
trugbild Apr 28, 2003 9:47 AMI really got a lot of problems with the transaction management (with both the declarative and the programmatic way).
I use jboss(2.4)/jetty and the jboss-db hypersonic.
Since the programmatic way didn't work, I decided to first make it declarative... but this also does not work.
I've written a simple servlet, which invokes the method transact() of a (also simple) Bean.
The Bean just updates a single entry in the database and then causes an exception. I expect the database-update not to happen, but when I test the entries, the db-update is done, even when the exception was thrown.
The code of the servlet is trivial. It just invokes transact().
The code of the bean is:
// connect to the database (which actualy works!)
// initialize statement-object
stmt.executeUpdate("UPDATE table1 SET word = 'two' WHERE word='one'");
// now the code that causes a System-Exception
throw new EjbException();
On the jboss-console, I get the following message:
[INFO,Default] ejbRemove()
[ERROR,Transactor] TRANSACTION ROLLBACK EXCEPTION:
javax.transaction.TransactionRolledBackException: null
Embedded Exception
10; nested exception is:
javax.ejb.EJBException: null
Embedded Exception
10
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:347)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:100)
....
I've looked at the documentation and found:
RollbackException exception is thrown when the transaction has been marked for rollback only or the transaction has been rolled back instead of committed. This is a local exception thrown by methods in the UserTransaction, Transaction, and TransactionManager interfaces.
So... everything should be correct... but if I get the entry, it is 'two' and not 'one' anymore. I tried a lot of things and didn't forget to change the db-entry back to 'one', everytime I test it.
I've also tested the entries in the ejb-jar.xml. I changed it to "Mandatory" and got the error message, that I have to invoke transact() from within a transaction... so I think it should work with "Required"!