aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Is this a Nested Transaction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Is this a Nested Transaction?" Watch "Is this a Nested Transaction?" New topic
Author

Is this a Nested Transaction?

Adilson Jardim
Greenhorn

Joined: Feb 27, 2004
Posts: 10
Hy,

I have a Stateless Sessin Bean CMT(trans-atributte= Required) that use a DAO with Hibernate, MBean service in jboss, like persistence layer.
The hibernate Mbean Service use UserTransaction interface supplied by container.

The following problem ocurred:

When a stand-alone remote client access this Bean and invoke sucessfuly my business method, that use dao objets, in the next time that any method that invoke any dao methods, this last throws a NullPointerException when the hibernate try take a getUserTransaction.

I learned that nested transactions are not suported in EJB. Would be any problem when any method those dao objects, call getUserTransaction inside a EJB CMT?


Thanks for all!

Adilson
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Adilson,

If I understood your post correctly you're asking whether it is possible to call EJBContext#getUserTransaction inside the ejb that is CMT ( <transaction-type>Container</transaction-type>).

The answer to this question is that it is illegal to use javax.transaction.UserTransaction in CMT ejb and the Container will throw java.lang.IllegalStateException if this is the case. javax.transaction.UserTransaction can be only used for BMT ejb (<transaction-type>Bean</transaction-type>).

Hope it helps


Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Adilson Jardim
Greenhorn

Joined: Feb 27, 2004
Posts: 10
Thanks Alex!!

This is the problem. I don�t call getUserTransaction() in my EJB context object.
As I said, the hibernate use the UserTransaction interface, therefore this is not visible for me.
In realy, I don�t understanding the problem. The call for the method getUserTransaction is made indirectly by a POJO and not by a EJB.

If exists a transaction, initiate by EJB, the DAO-hibernate object will go to use the same transaction or it starts a new transaction?

Thanks for any tip!!
[ July 19, 2004: Message edited by: Adilson Jardim ]
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Adilson,


The call for the method getUserTransaction is made indirectly by a POJO and not by a EJB.


It does not matter whether an ejb makes a direct call to EJBContext#getUserTransaction() or an ejb passes the control to POJO, which then makes a call to EJBContext#getUserTransaction().

If an ejb is CMT then all POJOs it talks to during a method execution can only perform operations that are legal for CMT beans.

Therefore, the following is illegal

CMT ejb -> POJO -> EJBContext#getUserTransaction()



Hope it helps
Adilson Jardim
Greenhorn

Joined: Feb 27, 2004
Posts: 10
Alex,
thanks for your help !!
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312

I learned that nested transactions are not suported in EJB.
Would be any problem when any method those dao objects, call getUserTransaction inside a EJB CMT?


You use hibernate with JBoss , so you can getUserTransaction from Session of Hibernate , you may not getUserTRansaction from EJBContext because some exception will occur when you set some config wrong.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this a Nested Transaction?