File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 is it possible to mix BMT and CMT?

 
Debopam Poddar
Ranch Hand
Posts: 51
Eclipse IDE Java jQuery
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible to mix BMT and CMT as in the next example. TestAddCommand method is under BMT and calls methods of AddCommand and RemoveCommand which is under CMT. Is this possible?


 
H Paul
Ranch Hand
Posts: 471
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is workable advisable?? (and why not?)

2. For experiment sake,

2.1 For RemoveCommand, instead of return null;
just throw new Exception();

2.2 Run TestAddCommand to see if you have a total rollback and especially for AddCommand in this experiment.
 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible to mix BMT and CMT. Moreover - the JTA started by the BMT can be reused by CMT, but not the other way around.
So if you have:

Client -> BMT -> CMT(REQUIRED), the CMT will reuse the transaction started by the BMT.
Client -> CMT -> BMT, the BMT will not be able to reuse the transaction started by the BMT.

HTH.

Cheers!

PS. This might be useful for you: http://stackoverflow.com/questions/7196242/why-does-cmt-commit-on-exit-of-ejb-method-when-transaction-attribute-is-required/7218283
 
Vinay Kejriwal
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Though not related to actual question here, I am puzzled with the usage (CMT annotation) in the TestAddCommand ejb, even though the class has got annotation (BMT).

Sorry for asking this if this is too trivial, I have started learning ejb recently and got confused seeing such a code.

Thanks
 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinay Kejriwal wrote:Hi,
Though not related to actual question here, I am puzzled with the usage (CMT annotation) in the TestAddCommand ejb, even though the class has got annotation (BMT).

Sorry for asking this if this is too trivial, I have started learning ejb recently and got confused seeing such a code.

Thanks


It is wrong. =)
 
Vinay Kejriwal
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Luan,

But shouldn't this code fail at compile time? I have seen this kind of code getting compiled without any error. So what exactly would be the behavior. Will jvm simply ignore this at runtime?
 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinay Kejriwal wrote:Thanks Luan,

But shouldn't this code fail at compile time? I have seen this kind of code getting compiled without any error. So what exactly would be the behavior. Will jvm simply ignore this at runtime?


Welcome =) About the new questions:

>shouldn't this code fail at compile time? I have seen this kind of code getting compiled without any error. So what exactly would be the behavior. Will jvm simply ignore this at runtime?

The code will not fail in compile time due there isn't this kind of evaluation during this process from the Javac process perspective. Maybe a good IDE may point this as a warning to make you aware that you might not get the desired behavior. The problem about the compile time, the Javac will just see if you have the correct syntax (liek keywords and their order to put in a nutshell) and the dependencies (to make the references inside the .class file). The real "magic" happens in the application server, which the container thread analyze your deployment package and create some proxies and/or aspects to provide the services described in Java EE specification. So, the container may also display some message of warn/error, depeding if it obligation d(if described in Java EE specification or not).

Best regards
 
Vinay Kejriwal
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Luan. It helped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic