Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

UserTransaction

 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Does the container provide us a UserTransaction object? How can I find it using WAS4.0?
What I did is:
context.lookup(java:comp/UserTransaction);
Should I use context.lookup(jts/UserTransaction);
Jun Hong
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jun Hong:
Hi guys,
Does the container provide us a UserTransaction object? How can I find it using WAS4.0?
What I did is:
context.lookup(java:comp/UserTransaction);
Should I use context.lookup(jts/UserTransaction);
Jun Hong


If you are inside a Session EJB you should always obtain the user transaction from the EJB context using getUserTransaction(). The spec is not clear on the result of trying to obtain the user transaction in any other way inside of an EJB. If you are in an EJB client, however, then the following should work:
initialContext.lookup("java:comp/UserTransaction")


------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
 
Jun Hong
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kyle,
Thank you for your repley.
My session bean uses a class called JNDIService. I don't want to pass EJBContext to this class. In JNDIService can I use initialContext.lookup("java:comp/UserTransaction")? I think it should work, right?
Also, is UserTransaction maintained by container. For example, if I have a datasource object. I am reponsable for create it on application server. Also, I give it a JNDI name, say, "fusion". In my bean's Deployment Discriptor, I map jdbc/fusion to fusion. I my bean code, I lookup java:comp/env/jdbc/fusion. For UserTransaction, I did create a UserTransaction object. Also, in my Deployment Discriptor I didn't map UserTransaction to any JNDI name. How come it works? Who is maintaning UserTransaction object.
Jun Hong
[This message has been edited by Jun Hong (edited October 03, 2001).]
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jun Hong:
Hi Kyle,
Thank you for your repley.
My session bean uses a class called JNDIService. I don't want to pass EJBContext to this class. In JNDIService can I use initialContext.lookup("java:comp/UserTransaction")? I think it should work, right?
Also, is UserTransaction maintained by container. For example, if I have a datasource object. I am reponsable for create it on application server. Also, I give it a JNDI name, say, "fusion". In my bean's Deployment Discriptor, I map jdbc/fusion to fusion. I my bean code, I lookup java:comp/env/jdbc/fusion. For UserTransaction, I did create a UserTransaction object. Also, in my Deployment Discriptor I didn't map UserTransaction to any JNDI name. How come it works? Who is maintaning UserTransaction object.
Jun Hong
[This message has been edited by Jun Hong (edited October 03, 2001).]


Jun, you are simply going to have to pass the transaction into your class. There is no other way to do it and still be compatible with the spec. The JNDI placement for the UserTransaction is determined by the container (you have no control over it) and it is intended to be used only outside of EJB's (e.g. not on a thread that could already be part of an EJB transaction). Go take a look at all of the examples in the EJB 1.1 spec -- they're pretty clear that you're supposed to obtain the txn from the SessionContext, as is the WebSphere documentation on the issue.
I've encountered problems with this before with other customers, and I'm convinced this is the only way to make it work in 4.0. Sounds like you've got a little bit of redesign ahead of you.
Kyle

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
 
Jun Hong
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Kely. Your reply is very helpful.
Jun Hong
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a test
 
I think I'll just lie down here for a second. And ponder this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic