aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Starting a client transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Starting a client transaction" Watch "Starting a client transaction" New topic
Author

Starting a client transaction

Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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?


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
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

Joined: Sep 29, 2002
Posts: 1683
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.
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1297
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?


BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting a client transaction
 
Similar Threads
xdoclet problem while generating ejb-jar.xml
Question about Security + Transaction
Transactions - DD
Transaction EJB session bean
"default" CMT behavior if trans attributes not specified