File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Choose Type Of Transaction  with EJB  (CMT VS BMT) 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 "Choose Type Of Transaction  with EJB  (CMT VS BMT)" Watch "Choose Type Of Transaction  with EJB  (CMT VS BMT)" New topic

Choose Type Of Transaction with EJB (CMT VS BMT)

somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
When i'm develope Application , it's use EJB and have transaction management.

So, Which i should BMT or CMT to manage transaction in my application ???

Java Developer, Thailand
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

CMT is always recommended.
You will use BMT when

1. You need to start multiple transactions within a single method.
2. You need your transaction to span mutilple methods.

Point 1 can be easily avoided by writing a method for each transaction.

Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
The comparison you are asking is about: managing transactions by yourself (BMP) and managing transactions with container help (at least, CMP).

blog -
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
In old days, when we still use EJB 1.x, as the containers are suck, we use BMP to control the transactions.

Nowadays, less and less people use BMP as the containers become more and more powerful, and EJB 2.0 even specified that, Entity bean can only use CMP!


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Peter Vennel
Ranch Hand

Joined: Dec 18, 2003
Posts: 46
Most important is you should know what you can do.

Message Driven Bean - CMT or BMT
Session Bean - CMT or BMT
Entity Bean - CMT only.

BMT - You have to Code
CMT - You can control through Deploy Descriptor attributes.

For CMT, Message Driven Bean can use only NotSupported and Requried.

BMT transactions are one way. They can propogate out to a CMT bean, but no other transaction can propogate into a BMT bean.

Th advantage inn BMT I see is that you can reduce the scope of a transaction.

Having said this, I would prefer CMT, unless there is something that I cannot do with CMT, but can do with BMT.

somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Thank you for all answer.
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
In some cases the only option is to use BMT.

Eg, with CMT Message Driven Bean message acknowledgment depends on whether the transaction rollbacked / committed. That is what spec's section "15.4.8 Message acknowledgment" says

Message-driven beans should not attempt to use the JMS API for message acknowledgment. Message acknowledgment is automatically handled by the container. If the message-driven bean uses container managed transaction demarcation, message acknowledgment is handled automatically as a part of the transaction commit. If bean managed transaction demarcation is used, the message receipt cannot be part of the bean-managed transaction, and, in this case, the receipt is acknowledged by the container.

Therefore, if MDB needs to acknowledge the message and rollback the transaction at the same time then the only way to do it is to use BMT.

[ July 22, 2004: Message edited by: Alex Sharkoff ]

Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
I agree. Here's the link:
subject: Choose Type Of Transaction with EJB (CMT VS BMT)
It's not a secret anymore!