File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes MDB - part of  a transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDB - part of  a transaction" Watch "MDB - part of  a transaction" New topic
Author

MDB - part of a transaction

Vijay Sing
Greenhorn

Joined: Apr 08, 2005
Posts: 7
Hi

I was wondering if anybody over here has a designed a solution where MDB was part a transaction. I am interested in how MDB can be rolled back if the transaction throws a exception.

If you look at Fig 64 of page 335 of the EJB(2.0) spec, it states that MDB can be part of the transaction and that it can be rolled back. Is this possible in any of the popular app servers like weblogic and websphere?

Regards
Vijay
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Vijay,

EJBs automatically roll back only system transactions. For manually rolling back application specific transactions (in CMT), one needs to call the setRollbackOnly method of the EJBContext interface. These rules apply to all EJBs, including MDBs. MDBs could also be involved in global (distributed) transactions. Weblogic for example allow setting the JMS connections to be XA-aware, which will make MDB transactions to follow the 2PC protocol.
Regards.


I think, therefore I exist -- Rene Descartes
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Please correct system transactions with system exceptions and application specific transactions with application specific exceptions in the first two sentences.
Sorry for any inconvenience...
Vijay Sing
Greenhorn

Joined: Apr 08, 2005
Posts: 7
Originally posted by Valentin Tanase:
Hi Vijay,

EJBs automatically roll back only system transactions. For manually rolling back application specific transactions (in CMT), one needs to call the setRollbackOnly method of the EJBContext interface. These rules apply to all EJBs, including MDBs. MDBs could also be involved in global (distributed) transactions. Weblogic for example allow setting the JMS connections to be XA-aware, which will make MDB transactions to follow the 2PC protocol.
Regards.


Thanks for responding . But it leads to another question !

Say for example Session bean A starts a transaction and calls MDB bean B and MDB bean C in the same transaction. My questions are :

1. As MDB can only have Required or unsupported type transaction attributes the transaction started in the Session bean A will not be propogated and hence MDB beans will never be part the bean A's transaction.

2. Also do we have to have XA type driver to make our beans part of a transaction?

Regards
Vijay
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704

1. As MDB can only have Required or unsupported type transaction attributes the transaction started in the Session bean A will not be propogated and hence MDB beans will never be part the bean A's transaction.

Basically what happens is that the producer and the consumer don�t run within the same transaction, mostly because of the asynchronous model of JMS messages processing rather than any transactional attribute (don�t forget: clients or other beans don�t interact directly with MDBs; they send messages to a JMS destination, where the MDB is a listener). The transaction propagation works the other way around when the MDB calls other ejbs. Then is better to have the MDB and your session ejbs enlisted within the same transaction.

2. Also do we have to have XA type driver to make our beans part of a transaction?

XA type drivers could be enlisted in global transactions that could span different transactional systems, like different databases, or different JMS destinations etc. If your application saves all the data in only one database, then you might not need XA drivers and 2PC protocol at all. WebLofic for example has another interesting feature that allows the server to simulate the 2PC protocol with non XA drivers. The way it works is very simple: Weblogic will first commit the non XA transaction. If this fail then Weblogic will use the standard 2PC protocol to inform other transaction managers that the transaction must be rolled back.
Regards.
Vijay Sing
Greenhorn

Joined: Apr 08, 2005
Posts: 7
Thanks once again. So MDB can't be part of anybody else's transaction, even not in another MDB's transaction.

Thanks
Vijay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB - part of a transaction