There are 3 ways UserTransaction can be obtained from JSF Context, ie. InitialContext object.
1. Using SessionContext or EJBContext from within your EJB implementation class. Only Bean-Managed transaction beans can have access
@Resources EJBContext context; UserTransaction utx = (UserTransaction) context.getUserTransaction();
2. Using InitialContext from your JSF controller class or utility class using the EJB
UserTransaction utx; try { InitialContext context = new InitialContext(); utx = (UserTransaction) context.lookup("java:comp/UserTransaction"); } catch(Exception e){}
3. Using InitialContext from your JSF controller class or utility class using the EJB
UserTransaction utx; try { InitialContext context = new InitialContext(); utx = (UserTransaction) context.lookup("java.transaction.UserTransaction"); } catch(Exception e){}
No comments:
Post a Comment