I am going through an EJB book and came across this statement.
A Message Driven Bean can use 'REQUIRED' tx attribute for its onMessage method.
What my interpretation is:
If some message is delivered in a queue by some client method, and that method has initiated some transaction.
Now 'REQUIRED' attribute applied to MDB means that the client producing the message should have some transaction initiated.
Else, MDB would create a new one.
Now, only when the client tx is successful, the MDB will be motified about the message in the queue, which means the client tx is already completed when MDB 'onMessage' method is called.
So, how does 'REQUIRED' tx fit here?
Your interpretation is incorrect. You have to remember that with queues, the processing is asynchronous. The client can send the message to the queue and it will be delivered. But, when the MDB takes it up for processing is in the control of the server. It may be immediate or an hour later. Basically, there is no direct link between the client and the MDB. So, it is obvious that a transaction cannot span this entire communication.
If a MDB has a @Required transaction attribute, that would mean that the code in the method runs under a transaction. For example, the MDB might process the message and write it to a DB - so, you can wrap this in a transaction.