in EJB 3.x for both the onMessage() method of MDBs and the @Timeout method of SLSBs and MDBs there is no transaction propagation. That is, there is no client for the execution of the method, so a transaction can't be possibly propagated.
When using Container-managed transactions, I would expect the two cases to accept the same javax.ejb.TransactionAttributeType. However, they don't.
For the onMessage() method, REQUIRED and NOT_SUPPORTED are the acceptable transaction attributes, whereas for @Timeout methods REQUIRED, REQUIRES_NEW and NOT_SUPPORTED.
In particular, for the @Timeout methods the spec says (par. 18.2.8):
Note that the container must start a new transaction if the REQUIRED (Required) transaction attribute is used. This transaction attribute value is allowed so that specification of a transaction attribute for the timeout callback method can be defaulted.
If I get this correctly, normally REQUIRES_NEW should be used here, but because REQUIRED is the default for an EJB, it is also allowed for @Timeout methods, giving it the same semantic as REQUIRES_NEW, since there is no possibility of a transaction to be propagated.
Questions:
- Is my understanding correct?
- Why isn't REQUIRES_NEW acceptable also in
onMessage()? Is it different somehow in respect of transactions?
UPDATE: The same goes for other cases where REQUIRES_NEW is supported: @Asynchronous and @PostConstruct/@PreDestroy methods.