Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

getUserTransaction for SLSB - spec vs HFEJB

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic