1 Reply Latest reply on May 14, 2010 7:16 PM by Cloves Almeida

    UserTransaction in non-EJB beans

    Cloves Almeida Newbie
      @SessionScoped
      public class MyNonEJBBean {
      
          @PersistenceContext
          EntityManager em;
      
          @Resource
          UserTransaction utx;
      
          public doSomeWork() throws Exception {
                   utx.begin();
                   Order order = em.find(Order.class, "ID");
                   order.setName("newname");
                   em.persist(order);
                   em.flush();
                   utx.commit();
          }
      



      The code above fails with a transaction not active exception on flush(). It seems that the injected EntityManager is not bound to the UserTransaction.