This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 is it possible to mix BMT and CMT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 is it possible to mix BMT and CMT?" Watch "EJB3 is it possible to mix BMT and CMT?" New topic
Author

EJB3 is it possible to mix BMT and CMT?

Debopam Poddar
Ranch Hand

Joined: Jun 21, 2005
Posts: 49

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

Joined: Jul 26, 2011
Posts: 391
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

Joined: Jul 13, 2010
Posts: 610

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


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Vinay Kejriwal
Greenhorn

Joined: Mar 15, 2012
Posts: 5
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

Joined: Feb 07, 2010
Posts: 162

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. =)


Please, visit me for some cool tech post at www.ourdailycodes.com
Vinay Kejriwal
Greenhorn

Joined: Mar 15, 2012
Posts: 5
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

Joined: Feb 07, 2010
Posts: 162

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

Joined: Mar 15, 2012
Posts: 5
Thanks Luan. It helped.
 
wood burning stoves
 
subject: EJB3 is it possible to mix BMT and CMT?
 
Similar Threads
EclipseLink1.1 inserts no data..
Strange behaviour of MDB and EJB
How to invoke the MIDlet ?
How to retrieve the string from textbox using Midlet to invoke the JSP
NullPointerException returned usig a StoredProcedureCall