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

    UserTransaction in non-EJB beans

    cjalmeida
      @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.

        • 1. Re: UserTransaction in non-EJB beans
          cjalmeida

          My bad. Had to call joinTransaction(). I was spoiled by Seam2 managed transactions. :)


          While Seam3 Persistence is pending a release, I developed my own poor man @Transactional interceptor. Even though I still have to call joinTransaction(), a lot of boilerplate code is gone.