• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMT vs. BMT

 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB 3 in Action....

Page 201...

6.3.4 Pros and cons of BMT

"If you are using a stateful session bean and need to maintain a transaction across method calls, BMT is your only option."

I am not able to imagine this case ( I am not able to understand the case where CMT won't be helpful).
Please help me to understand above statement.

Thanks....
 
Jonathan Elkharrat
Ranch Hand
Posts: 170
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
imagine tou have an account bean with 2 method, one to add money and another to withdraw.
if you want to make a transfer you need to call these 2 methods successively.
if either of the method fail while the other one complete the data would be corrupted.
so you need to call these two methods in one transaction.
CMT commit at the end of the method so you have to do it manually... (BMT)
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply....

Is that mean in SFSB will begin transaction in method 1 (deduct)
and commit the tranaction in method2 (add)?



If above example is the case then, is this a good code where transaction is started in one method & transaction is committed in other method?

If above example is not the case then,
I am not able to understand the situation...
Can someone please write structure of class(es)?


 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it will be more like

 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for your reply.....





1. I hope you meant sfsb1.add() (not sfsb2.add()).

2. if client is an EJB then isn't it possible,




3. if client is (non-EJB) a web-client then
CMT is not possible in any case... isn't it.....


"If you are using a stateful session bean and need to maintain a transaction across method calls, BMT is your only option."

need to maintain a transaction across method calls - at client side
BMT is your only option - where is the question of BMT or CMT in SFSB? isn't it client's responsibility to take care of transaction(s).

I am still confused because I believe author is talking about transaction management within the SFSB.
Please help....

thanks....
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get confused with your question. I think the authors have already stated very clearly.
If SFSB A has 2 business methods m1 and m2, you want to begin transaction in m1 and commit/rollback transaction in m2, if you use CMT how can you do that? It's impossible with CMT, because CMT begin transaction before invoke a business method and commit/rollback after the invocation.

isn't it client's responsibility to take care of transaction(s).

No, don't do that. Clients should not know about transaction.
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic