0 Replies Latest reply on Jul 9, 2010 3:25 PM by dbredesen

    calling a transactional helper method from within a non-transactional EJB method

    dbredesen

      So I'm trying to call a transactional helper method from within a non-transactional EJB3 service method.  Since the EJB method has no transaction, a new one cannot be created through the local call to the helper method, because there is no txn wrapper initiated by the container.

      The usual way around this is to get a handle to the local EJB instance via the SessionContext, and call the method through the handle.  So:
      @Service
      public class MyEJB {
        @SessionContext ctx;

        public void myPublicButNonTransactionalMethod() {
          ((MyEJBLocal) ctx.getEJBLocalObject()).helperMethod();
        }

        @TransactionAttribute(REQUIRED)
        public void helperMethod() {
          entityManager.persist(someObj);
        }
      }
      Unfortunately, this doesn't seem to work in JBoss, and the errors are silly.  I have tried 3 different approaches:
      ctx.getEJBLocalObject()

      java.lang.IllegalStateException: NYI

       

       

      ctx.getEJBObject()

      java.lang.IllegalStateException: NYI

       

       

      ctx.getBusinessObject()

      java.lang.IllegalStateException: Not implemented

       

       

       

      Isn't there any way to call the helper method to get a transaction without resorting to an Initial Context / JNDI lookup / etc??

       

      This is JBoss AS 5.1.0, using Hibernate.

       

      Thanks,

      --d