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....
posted 5 years ago
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.