I just did a test and, fortunately, it is not the EJB behaviour. I have this code:
Code:
// this is a method in a stateless session ejb with transaction required
public void methodA(...){
// if exception occur, always throw RuntimeException
}
// another method in the same session ejb with transaction required
public void methodB(...){
try{
methodA();
}
catch(Exception e){
// exception situation can be recovered
// do something else
}
// continue ...
}
After methodB returns, transaction get committed. The failure of methodA doesn't cause the whole transaction roll back.
The test runs on weblogic 8.14 sp4.
For the time being, I have to use programatic transaction control, like this:
Code:
PlatformTransactionManager transactionManager = getTransactionManager();
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(this.getTransactionAttribute());
TransactionStatus status = transactionManager.getTransaction(def);
try{
// call other methods that use transaction
if ( status.isNewTransaction() ) { // only the originator can commit or rollback
transactionManager.commit(status);
}
}
catch (Throwable t) {
if ( status.isNewTransaction() ) {
transactionManager.rollback(status);
}
throw t;
}