Search code examples
java-ee-6ejb-3.1message-driven-bean

MessageDriven Bean: is MessageDrivenContext#setRollbackOnly() in Java EE 6 still required?


I have a Message Driven Bean (EJB 2.1) which does the following:

public void onMessage(javax.jms.Message msg) {
try{
...
} catch (JMSException e) {
        e.printStackTrace();
       getMessageDrivenContext().setRollbackOnly();
}

I want to convert such bean into an EJB 3.1 one and I wonder if is the setRollbackOnly() explicit call (and hence the injection of a MessageDrivenContext Resource within the bean) still needed? In other words, doesn't the container automatically rolls back the transaction when a JMSException is thrown? What happens if I omit such method call?

Thanks!


Solution

  • It is still needed. JMSException is not a special case. It doesn't cause transaction rollback. If you omit setRollbackOnly and no other part of code causes rollback, then transaction is committed in the end.