aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB-> java ->new EJB. What will be Txn status in the new EJB and should ejb-ref? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB-> java ->new EJB. What will be Txn status in the new EJB and should ejb-ref?" Watch "EJB-> java ->new EJB. What will be Txn status in the new EJB and should ejb-ref?" New topic
Author

EJB-> java ->new EJB. What will be Txn status in the new EJB and should ejb-ref?

Gul Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
1- If an EJB is calling a java class and that java class is a client to another EJB, Do i also have to add that EJB to my ejb-ref?

2- This first EJB starts a transaction, will the second EJB (called as in above scenario) run in a new transaction?

Thanks Appreciate ur help.
Bhagyashree Jayaram
Greenhorn

Joined: Jun 28, 2004
Posts: 1
Originally posted by pervaiz gul:
1- If an EJB is calling a java class and that java class is a client to another EJB, Do i also have to add that EJB to my ejb-ref?

2- This first EJB starts a transaction, will the second EJB (called as in above scenario) run in a new transaction?

Thanks Appreciate ur help.


Yes you need to add the ejb-ref for the first ejb indicating a reference of the second ejb in the first ejb.

Whether the 2nd ejb runs in the same transaction depends on the transaction attribute you have set.Use Required so that if there is already a running transaction it will run init and otherwise it will run in a new transaction.
Gul Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
Thanks that worked. another question.
If a "java bean client" is calling many session EJBs and every EJB method has Txn Attribute 'Required' than will all the EJBs run in the same Txn or new ones for everyone.
I mean, the ejb called on the first line will create a new Txn for itself and than returns to the client. next line call another EJB with Required txn attrib, would the new EJB run in the previous EJB's txn or create a new one (If so then at what point is the last txn committed).

thanks and regards
GUL
Amit Jaipaul
Greenhorn

Joined: Jul 17, 2003
Posts: 16
Hi,

Each call from the client will start a new transaction and will be committed before returning to the client.
Dan Johnsson
Greenhorn

Joined: May 31, 2004
Posts: 24
Originally posted by Bhagyashree Jayaram:


Yes you need to add the ejb-ref for the first ejb indicating a reference of the second ejb in the first ejb.


A clarification why it is so:

The EJB container make no difference between code that is "in the bean" and in other classes called by the bean. The "helper class code" could have been inlined in the bean class and the container would see no difference.

So, even if code is broken out of the bean-class to helper classes, the code is nevertheless "in the bean".

Dan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB-> java ->new EJB. What will be Txn status in the new EJB and should ejb-ref?