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

EJB transaction

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bean managed tx are useful when one needs to define several tx's within a single method.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic