Will transaction be rolled back?
Hello,Today I was investigating some old code that is run in a jee-application.
This is run in a container managed jee-server (weblogic).
I stumbled over this code (a bit simplified):
public class AException extends Exception {
}
@Stateless
@TransactionAttribute(REQUIRED)
@TransactionTimeoutSeconds(1000)
public class JobEJB implements Job{
public void update() throws AException {
boolean ok = true;
try {
//do some update in a databse
for(int i = 0; i < 100; i++)
if(i==50) {
XXXX
}
}
}
catch (AException e) {
ok= false;
sessionContext.setRollBackOnly();
throw new AException();
}
catch (RuntimeException e) {
ok= false;
throw new AException();
}
finally {
System.out.println("Job: " + ok);
}
}
}
I would say that if XXX above is replaced with:
throw new AException();
...then the transaction will be rolled back since setRollBackOnly() is called.
BUT if XXX below is replaced with:
throw new RuntimeException();
...then the transaction will be NOT be rolled back, since the exception is catched and I guess the app server will not know about it, right?.
Am I right?
Best regards
Fredrik