• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JPA UserTransaction Injection...

 
Ranch Hand
Posts: 160
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ...!!

Can anyone please tell me that when to use UserTransaction and when not to use it. Because i am getting errors sometimes when i have not used UserTransactions (in case of adding record to database through JPA in JSF managed bean) and sometimes when i don't even put UserTransaction in my code then also it works perfectly.( in case of Remote EJB bean inserting record into database)..

Therefore i am little confused regarding this. Can anyone please tell me when to use it and when to not... I read EJB 3.0 and JPA specification but still i am not clear with it..

Thanks in advance....
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPA can be configured to be JTA or RESOURCE_LOCAL (in your persistence.xml). When using JTA you must use JTA UserTransaction, with RESOURCE_LOCAL you can use JPA transaction.

A EJB SessionBean (or EJB MessageDrivenBean) will automatically begin and commit a JTA (UserTransaction) around any method call, so you don't need to call UserTransaction directly. Anything else, (JSF, JSP, etc.) will need to manage its own JTA transaction.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Transactions
 
reply
    Bookmark Topic Watch Topic
  • New Topic