I'm developing an application in which I have a method in a session bean where I create instances of two differents Entity beans, finding by PK. I do some updates for both, and intentionally, I throw an exception in the ejbStore method of the Entity bean that a found last. I hope that occurs an rollback of the transaction, but the changes made in the first entity bean not rolled back !.
I revised the transaction attributes in the deployment descriptor, and they are correctly, somebody knows what is wrong ??
As I know the only exception that
can roll back the transaction is system one.
So be sure that you throw SystemException
or rollback transaction manually
You can throw a system exception by e.g. throwing an EJBException (which is a RuntimeException, which means that you don't have to declare it in the method signature). Also make sure that the transaction attributes of all beans are set to (for example) REQUIRED, so that all the beans definitely participate in the same transaction.
I would not recommend throwing one unless you have a system problem you can not recover from.
If you throw an System Exception the bean throwing the exception gets destroyed without its ejbRemove being called.
Chapter 18 in the EJB2.0 spec talks about exceptions.
I have the same problem as Adrian, so if you suggest not to throw system exception, what will you do to rollback the transaction?