Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Choose Type Of Transaction with EJB (CMT VS BMT)

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The comparison you are asking is about: managing transactions by yourself (BMP) and managing transactions with container help (at least, CMP).
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Nick
 
Peter Vennel
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Peter.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all answer.
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic