• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

getUserTransaction() within ejbCreate()

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

For a stateless session bean with BMT, is sessionContext.getUserTransaction() a valid call within ejbCreate()?

thanks!!

RL
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope
 
Ryk Lee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Nope



Thanks a lot! (sorry it's a little bit late)
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May i know why? Thanks.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Stateless beans, ejbCreate is called by Container which is associated with bean creation. Hence there is no place for UserTransaction to be initiated.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can see scbcd 100% in your signature.
Are you kidding with this kind of questions or you want to test others?
I mean i am sure K&B both would not have got 100%.
???
 
Ranch Hand
Posts: 138
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
According to the table in page 90 in the EJB2.0 specification it is legal to call getUserTransaction() in a ejbCreate() method. Is it a mistake in the specs then ?
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you refer to HeadFirst EJB page 228, it is mentioned that you cant get a transaction reference and call methods on it(BMT beans) in ejbCreate and ejbRemove() methods.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rohit,
I think what they mean on page 228 is calling methods apart from getting user transaction.In the spec it we see on page 90 for business methods they have specifically mentioned UserTransaction methods apart from getUserTransaction.
Even though we can getUserTransaction we can't call methods.That is what it seem to imply.Rohit since you seem to have implemented the code why don't just try out this and try calling methods?
 
Mike Pandey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys

I see it in this way.
The UserTransaction is avaliable at java:comp/UserTransaction namespace in bean env and since in ejbcreate the Jndi access is there you can get a reference to UserTransaction. But since there is no security info available at this juncture for Stateless beans one cannot call methods on UserTransaction reference to start a valid transaction.
The same applies to MDB ejCreate and ejbRemove.

Thanks
 
Rajan Murugan
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UserTransaction has the following methods

begin()
commit()
getStatus()
rollback()
setRollbackOnly()
setTransactionTimeout()

only.Where did the issue of security come up here?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Reason I could think of is that, calling the ejbCreate() is assosiated with the creation of the bean, and this may happen anytime in a session bean

where as a transaction is associated with a business method call.

these both are in no way related for a stateless session bean.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i believe ejbCreate in SLSB is called with an unspecified transaction context... that's why getUserTransaction wont' work...

rgds
marco
 
Rajan Murugan
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can call getUserTransaction but we cannot call methods on it since there is no transaction.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,we can call getUserTransaction() in ejbCreate() method of SLSB.
This is 100% correct.

Sudhakar(SCJP1.4)
M.C.A(2006)
Satyam.
 
reply
    Bookmark Topic Watch Topic
  • New Topic