Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB transaction

 
Maggy Zhang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nandu Arni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bean managed tx are useful when one needs to define several tx's within a single method.
 
Yogesh Mathur
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic