As we all know that client's transaction context is not associated with MDBs, since the sender and the receiver are completely decoupled from each other. That said,how can we set the transaction attribute REQUIRED to the message listener method.And also clarify me why cant we use the REQUIRED_NEW,because it doesn't cares about the client's transaction context regardless of it exists or not.
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Your message bean may access a database to do its stuff, so you need to tell which attribute to use for transactions. It doesn't matter whether or not there's a client. You need to tell the container if you need a new transaction or not. Either REQUIRED or NOT_SUPPORTED are used. Some other attributes (like REQUIRES_NEW) imply that a client may be there, and that its transaction will be suspended. Some others imply that an exception will be thrown, but nobody will catch it.
I believe only "requiresNew" attribute will force to start new transaction on method invocation.
For MDB "required" attribute means, the mdb will run in global transaction started by ejb container, this transaction starts before the onMessage itself.
Implies the OnMessage method never starts the transaction , it always runs inside the already started transaction from the container.[Since this transaction completion is tied with the acknowledgement,message redelivery etc, That's is the reason it does not support the attribute type "requiresNew"]
Hi Senthi ,
What Trasactional context of the client(who sends the message) is got to do with the message consumption [asynchrnously], Both should be in different transaction and does not depend on each other. [ June 28, 2007: Message edited by: rajan singh ]
The JMS specification requires that the transaction be started before the dequeuing of the message. Either the EJB container or the messaging provider can start a new transaction before the delivery of the message and, therefore, before the invocation of the onMessage() method.
This is why the Required transaction attribute is suitable and the RequiresNew transaction attribute is not suitable.
or the messaging provider can start a new transaction
Could you explain what you mean ? Does it mean that the transaction will be propagated ? How ?
Joined: Jun 08, 2005
The transaction will be propogated from the container.
Below is the reason why "requiresNew" is not suitable for MDB.
If the transaction is commited, the message will be considered as delivered otherwise the container may keep the message alive.
Now suppose the the transaction type is "requiresNew" then the scope of OnMessage will demarcate the transaction boundry and calling transaction[initiated by conainer] will be suspended and will not bother what happened to new transaction[onMessage's new transaction].In this case container will not have any clue what happened to the message[ Please note container associate successfull message delivery with the commit of the trasaction ]
That is why MDB does not have requiresNew attribute.
Joined: Mar 13, 2006
Spec 5.4.12 says
If the bean is specified as using container-managed transaction demarcation, either the REQUIRED or the NOT_SUPPORTED transaction attribute must be used for the message listener methods, and either the REQUIRED, REQUIRES_NEW, or the NOT_SUPPORTED transaction attribute for timeout callback methods.
When the REQUIRED_NEW attribute cannot be specified to the onMessage() method,then how on earth would you use this for the time out method.