This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Bean managed transactions with MDBs in EJB 3.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Bean managed transactions with MDBs in EJB 3.1" Watch "Bean managed transactions with MDBs in EJB 3.1" New topic
Author

Bean managed transactions with MDBs in EJB 3.1

Ajay Dhar
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
This is a question regarding a statement in Ivan Krizsan's study notes on page 165, and the EJB 3.1 spec in sections 4.3.15 and 13.6.5, about reasons for using bean managed transactions. The statement I don't understand is:

Bean managed transactions "can be used with message driven beans, in order to be able to acknowledge a message even through the transaction rolls back."

I thought when BMT was used with an MDB, if the transaction rolls back, the container does not acknowledge the message. How can the message be acknowledged if the transaction rolls back?

Thanks,
Ajay


OCPJP 6, OCEEJBD 6, GIAC Secure Software Programmer-Java (GSSP-Java)
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

According to EJB 3.1 Ch 3.10.4:

If your MDB uses BMT, message receipt is not part of the transaction. If your MDB uses CMT with Transaction attribute NOT_SUPPORTED, message receipt is not part of the transaction (because there is none)

The way I understand it, is that CMT with transaction attribute REQUIRED means that the acknowledgement of your message is linked to your transaction. If your transaction rolls back, the message will be redelivered.

If you use CMT with transaction attribute NOT_SUPPORTED, or if you use BMT, the message will only be redelivered if the onMessage method throws a RuntimeException. Acknowledgement is handled by the container, but the transaction isn't. So in this case the transaction rollback will have no bearing on the redelivery of the message (with NOT_SUPPORTED because there is none, with BMT because it's not managed by the container, and the message acknowledgement is).


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean managed transactions with MDBs in EJB 3.1