-
1. Re: Rolback Problem
kabirkhan Apr 20, 2004 12:19 PM (in response to sharris)You are throwing the wrong exception.
You should generally not be creating your own RemoteExceptions (they are meant for use by Java when something goes wrong with the remote communication). This is the case in EJB 2.0 at least, maybe this was different in EJB 1.1? I can't remember.
For rollback to take place you need to do one of:
a) If you want to rollback the transaction as a result of throwing an exception, that exception needs to inherit from RuntimeException, and the "standard" exception you would thrown in your case is javax.ejb.EJBException which inherits from RuntimeException.
b) If you throw an exception that does not extend RuntimeException (such as RemoteException, or any application exceptions defined by you etc.) you need to call setRollbackOnly() on the EJBContext of your EJB for rollback to take place.
Why this worked with hsqldb I don't know.
So your code should be (for a)):
createFoo( ) {
try {
fooHome.create(); //create entity bean
bar.validate(); // get a RemoteException
catch (Exception e) {
throw EJBException; //entity bean creation should rollback
}
Cheers,
Kab -
2. Re: Rolback Problem
sharris Apr 22, 2004 1:43 PM (in response to sharris)I tried both of these suggestions - throwing an EJBException and calling setRollbackOnly on the EJBContext at the end of createFoo(). In both cases a TransactionRolledbackLocalException is generated, but the creation of the Foo entity bean is NOT rolled back in the db.
So then I figured it might be something in the way that our mysql was configured. When I ran the mysql admin tool, I found that the table_type (ie., storage engine) comes up myisam which does not support transaction rollbacks. Remember that 4.X versions of mysql ship with innodb and bdb starage engines which do support transactions. Can this be the problem or does JBoss reset the storage engine? I suppose what I'm asking is whether there is some required or preferred mysql configuration for transactions or whether the JBoss just handles this. -
3. Re: Rolback Problem
sharris Apr 23, 2004 3:17 PM (in response to sharris)I'm still wondering about how JBoss handles setting mysql storage engines (if it does). By the way, using hypersonic, throwing a RemoteException from BarService.validate() causes the transaction initiated by validate's caller (FooService) to be marked for rollback (and it is rolled back). I can see it in the debugger when I look at the transaction in the EJBContext. It goes from having a status of 0 (ACTIVE) to 1 (MARKED_FOR_ROLLBACK). I realize this rollback should happen only if a RuntimeExceptions like EJBException is thrown, but what I see is what I see.
-
4. Re: Rolback Problem
mpforste Apr 25, 2004 3:05 AM (in response to sharris)What Database and Table system are you using,
I had problems with a transaction not rolling back on MySQL using MyISAM tables, I switched to InnoDB and it works, Apparently MyISAM doesnt suppot ACID transactions but innoDB does.