Which of the following are true regarding a bean with bean managed transaction demarcation ?
a) the bean must be a session bean or a message-driven bean
b) The bean instance that starts a transaction must complete the transaction before it starts a new transaction
c) The bean may use nested transactions
d) If it is a stateless session bean, it must commit a transaction before a business method or a timeout callback method returns
e) If it is a message-driven bean, it must commit a transaction before its message listener method returns
The correct answers are a), b), d)
I agree that these are correct, but e) is correct, too.
e) is considered incorrect with the explanation
"This is not fully true. A message driven bean may commit the transaction even in a timeout callback method."
However, core spec 13.6.1 states
If a message-driven bean instance starts a transaction in a message listener method or interceptor method, it must commit the transaction before the message listener method (or all its interceptor methods) returns.
Remarks:
1. enthuware's explanation may be based on a misinterpretation of core spec 13.3.3:
A message-driven bean instance must commit a transaction before a method listener method or a timeout callback method returns.
2. From a functional point of view: core spec 18.2
The timeout callback method invocation for a timer that is created for a stateless session bean or a message-driven bean may be called on any bean instance in the pooled state.
If the instance that performs the timeout callback method can be choosen arbitarily, how should it know that it has to complete a transaction started by a message-listener method of some other instance ? This couldn't work.
3. The same holds for stateless session beans.