Win a copy of Java Challengers this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

can non-ejb client pass its transaction to ejb?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I know a BMT bean A can make use of EJBContext.getUserTransaction(). If this bean calls any CMT bean B then depending upon the transaction-attribute specified in DD the transaction from bean A will be passed to bean B.

Now suppose the client of bean B is not an ejb(say a servlet or swing) and wants to pass its trasaction to the CMT bean. Is this possible? Since client is not an EJB it will will not have UserTransaction reference. Which transaction object it should use. How this can be done?


Thanks
Prakash
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can get a UserTransaction Object either from the EJBContext or thru JNDI in an EJB.
You can get hold of a UserTransaction Object using JNDI in a servlet and call EJBs. The EJBs get this transaction passed from the servlet based on the CMT transaction attribute.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container is required to make the JTA available at the location java:comp/UserTransaction. This is what you use to look it up in JNDI, as the previous poster said.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example of using transactions from a non ejb client:
javax.transaction.UserTransaction userTran;
Context ctx = new InitialContext();
userTran = (javax.transaction.UserTransaction)ctx.lookup("java:comp/UserTransaction");
userTran.begin();
//business methods
userTran.commit();
This example is straight from the transactions chapter of Mastering Enterprise JavaBeans by Ed Roman et al. The book is freely downloadable at theserverside.com
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic