File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB transaction 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 transaction" Watch "EJB transaction" New topic
Author

EJB transaction

Maggy Zhang
Greenhorn

Joined: Dec 17, 2001
Posts: 8
There two way using trasanction in EJB(Session Bean). One way is that I can handle transaction by UserTransaction through JNDI or by configuring transaction attribute in ejb-jar.xml. When should I use first way ? when should I use the second way?
The second question is:Can I use UserTransaction in javabean by JNDI lookup , suppose that the javabean run inside application server?
Thanks
Priyank RASTOGI
Greenhorn

Joined: Mar 29, 2001
Posts: 6
When should I use first way ? when should I use the second way?
UserTransaction is supposed to be used only when the developer wants to take care of transaction semantics... when to start/end a transaction... for example EJB's with Bean-Managed Persistance...OR say Session EJB where you might want to start a transaction in one method and commit in some other...
Can I use UserTransaction in javabean by JNDI lookup , suppose that the javabean run inside application server?
yes, you can lookup for UserTransaction and use it...
RaviShanker Tippa
Greenhorn

Joined: May 05, 2002
Posts: 15
To be Precise,
If the transaction is of type Bean Managed,then u can use UserTransaction.This apply only to sessionBeans not Entity Beans as they always are COntainer Managed Transactions.


RaviShanker Tippa,<br />Syntel India Ltd
Nandu Arni
Greenhorn

Joined: Jan 26, 2002
Posts: 8
We use UserTransaction in session bean, when the dev wants to write the transaction logic. Becoz some transaction logic may be fixed, irrespective of the business situations. Suppose if we take a simple bank aplication, the "withDraw" method always need a trasaction to be set in a unique way. so if the transaction logic needs to be changed from deployment to deployment, we go for Container managed. i.e XML files to configure. otherwise we can go for writing the transaction logic embed inside the code.
Is is confused still..... hello_nandu@yahoo.com
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Bean managed tx are useful when one needs to define several tx's within a single method.


Groovy
Yogesh Mathur
Greenhorn

Joined: Apr 18, 2002
Posts: 17
Originally posted by RaviShanker Tippa:
To be Precise,
If the transaction is of type Bean Managed,then u can use UserTransaction.This apply only to sessionBeans not Entity Beans as they always are COntainer Managed Transactions.

I thought Entity Beans can be Bean Managed also. As far as Session Beans are concerned, I think only statefull session beans could be stored in Persistent storage.
Can anybody throw some light weather Session beans (Statefull) could be Bean Managed?


Yogesh
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Originally posted by Maggy Zhang:
When should I use first way ? when should I use the second way?

BMT allows you to have a better control over the scope of the transaction, also if you�re using statefull session beans you can use it to make a transaction scope around more than one method call, with CMT your control over transactions is restricted to methods.

The second question is:Can I use UserTransaction in javabean by JNDI lookup , suppose that the javabean run inside application server?

The specification API provides it and the method to get it stays like this(this method belongs to the EJBContext interface):
Yogesh Mathur
Greenhorn

Joined: Apr 18, 2002
Posts: 17
Originally posted by Yogesh Mathur:

I thought Entity Beans can be Bean Managed also. As far as Session Beans are concerned, I think only statefull session beans could be stored in Persistent storage.
Can anybody throw some light weather Session beans (Statefull) could be Bean Managed?

I am sorry. I am new to EJB. I got confused between Persistence and Transactions. Actually its analogous- session beans can have CMP, CMT & BMT whereas entity beans can have BMP, CMP & CMT.
Sorry for such silly mistake.
 
GeeCON Prague 2014
 
subject: EJB transaction