aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes getUserTransaction for SLSB - spec vs HFEJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "getUserTransaction for SLSB - spec vs HFEJB" Watch "getUserTransaction for SLSB - spec vs HFEJB" New topic
Author

getUserTransaction for SLSB - spec vs HFEJB

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
For SLSB:

Spec says that the getUserTransaction can be called from ejbCreate and ejbRemove (spec page 90).
HFEJB says that - get a transaction reference and call methods on it (BMT) - is not allowed from ejbCreate and ejbRemove (page 228)

What is correct of the above?
Balaji VR
Ranch Hand

Joined: Mar 22, 2006
Posts: 76
Tricky :-) Is n't it? Here is a quick reply!

What it means is that, you could be able to get a reference to UserTransaction interface in ejbCreate() & ejbRemove() methods. But you could not call any of the methods on it. (LIKE begin(), commit() ....)

But, you can do that from business methods...Just have a closer look at the Table 3 in page 90 (SPEC)

USER TRANSACTION METHODS is note mentioned against ejbCreate & ejbRemove...:-)

Hope it clears your doubt!
Happy learning!!!


Bala<br />SCJP 1.4 98%<br />SCBCD 1.3 -- 88%
Frederic Esnault
Ranch Hand

Joined: Feb 13, 2006
Posts: 284
Hi,

Balaji is right.

Think about getUserTransaction method as something that gives you a reference to a "transaction management interface" (which is exactly what it is ).

You can get the interface to it anytime (as I say in my doc : as soon as the bean becomes a bean, which means as soon as ejbCreate is called (except for entity beans, but they cannot use BMT...)), but you can use it to manage transaction only when you get a meaningful transaction context.

Hope this helps


SCJP 5 - SCWCD 1.4 - SCBCD 1.3 - Certification study documents/resources: http://esnault.frederic.free.fr/certification
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Thanks Balaji and Frederic for quick reply ...

You can get the interface to it anytime ... but you can use it to manage transaction only when you get a meaningful transaction context.


I see another scenario here.

For ejbCreate, ejbRemove, ejbActivate, ejbPassivate of SFSB, HFEJB says that
Not Allowed:
- force transaction to rollback (CMT)
- find out if transaction has been set to rollback (CMT)
Allowed:
- get transaction reference and call methods on it (BMT)

Here, why BMT is allowed to call methods on the UserTransaction? These methods doesn't run under a meaningful transaction context.
Rahul Mishra
Ranch Hand

Joined: Jan 22, 2006
Posts: 211
Heyyyyyyyyyyyy,

You can NOT get an interface to it any time...if you are not allowed to get the interface of User Transaction through JNDI and you attempt to get it , it gives you a javax.naming.NameNotFoundException..

Check the EJB Specs..its written..


OCMJEA/SCEA, SCDJWS, SCBCD 1.3, SCJP 1.4
My SCEA experience:http://javalogue.blogspot.com/
Frederic Esnault
Ranch Hand

Joined: Feb 13, 2006
Posts: 284
Yes, you're right, but when I said "anytime", I meant that you don't need to have a transaction context.

About BMT SFSB and call UserTransaction methods, I'll check this too. This is strange.
Frederic Esnault
Ranch Hand

Joined: Feb 13, 2006
Posts: 284
From the spec (first paragraph page 81), it is said that ejbCreate, ejbRemove, ejbPassivate and ejbActivate from a CMT session bean execute in an unspecified transaction context. This is why get/setROllbackOnly is not allowed.

About BMT stateful session beans, as soon as ejbCreate is called, they are linked to a user, so they have a UserTransaction they can use immediately, as developped in the bean.

CMT does not allow tx in these methods, but BMT (where tx management is left up to the bean provider responsability) doesn't restrict tx usage in these methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getUserTransaction for SLSB - spec vs HFEJB