aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transaction attributes in MDBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transaction attributes in MDBs" Watch "Transaction attributes in MDBs" New topic
Author

Transaction attributes in MDBs

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
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%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
Assume the client(who sends the message) has a transactional context and
the message listener method has the transaction attribute type specified as 'REQUIRED', what will the container do.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

There is no client, so REQUIRED will always force a new transaction to start.
rajan singh
Greenhorn

Joined: Jun 08, 2005
Posts: 17
Hi Satou,

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 ]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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 ?
rajan singh
Greenhorn

Joined: Jun 08, 2005
Posts: 17
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.
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
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.

isn't the timeout method part of the MDB?.
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
Ranchers, awaiting your replies
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction attributes in MDBs