• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction attributes in MDBs

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no client, so REQUIRED will always force a new transaction to start.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers, awaiting your replies
reply
    Bookmark Topic Watch Topic
  • New Topic