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.
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 ]
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.
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.
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.
isn't the timeout method part of the MDB?.