• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Starting a client transaction

 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I just clarify my understanding of something.

Suppose there is a client (which is outside the EJB container) that needs to call a stateless session bean method to update the DB and then get confirmation from the user that the transaction is OK. Should this be done as follows.

1. Client gets a UserTransaction and invokes the begin() method.
2. Client invokes bean method.
3. Client prompts user for confirmation (assume that the bean method returns OK)
4. If user says OK, client imvokes commit(), else invokes rollback().

Furthermore, should the bean be CMT, ie the DD has this entry:

<transaction-type>Container</transaction-type>

And with this transaction attribute:

<trans-attribute>Required</trans-attribute>

My thinking is that the client transaction will propogate into the CMT bean and that the bean's method will run in the existing transaction as it has the Required attribute.

Does this make sense?
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should ask Roger, he has loads of answers ;-)

I'm not sure I fully understand the scenario, but I'll throw something out, and you can give me more if I'm missing something.

I presume that your client is not a bean (from some other EJB container) since it's interacting with a user. To get access to UserTransaction, you'd have to have access to an EJBContext object, right? If we were a bean, then we'd get that context when we were just getting started, and we'd save it in an instance variable. But where is this client going to get the reference to an ejb context?

--Dale--
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For bean-managed transactions, a session bean obtains the UserTransaction object via the EJBContext using the getUserTransaction() method.

In other environments such as a web container, a JMS server, a thick client (which is what I was thinking of when I did my post), you obtain a UserTransaction object via JNDI. There must be a JTS-capable server to deliver the object.

Typically, the server provides the JNDI look-up name either directly or via a system or server property. For example, with WebLogic, you use JNDI to return a reference to a UserTransaction object for the WebLogic Server domain.
 
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i wanna handle transaction programmtically in client code do I need use global transaction XA driver for the datasource in the application server?
and the code to do it is the same as BMP except BMP I get it from EJBContext? and in client side I have to look it up like getting a remote interface of a bean?
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic