1 Reply Latest reply: Nov 4, 2011 4:26 AM by René van Wijk RSS

    Ejb exception

    594629
      Hi all;

      i am using the code below to call a stored procedure and do an insert in the database, but what i notice not all record are going throught , for some i am getting an EJB exception .Please help

      em.createNativeQuery("BEGIN FULFILL_STOCK(?1,?2,?3,?4,?5,?6,?7,?8,?9); END;")
      .setParameter(1, p_organization_code)
      .setParameter(2, p_subinventory_code)
      .setParameter(3, p_locator)
      .setParameter(4, p_trx_level)
      .setParameter(5, Long.parseLong(p_inventory_item_id))
      .setParameter(6,new Long(p_quantity).longValue())
      .setParameter(7,p_serial_number)
      .setParameter(8,p_transaction_reference)
      .setParameter(9, p_source_system)
      .executeUpdate();

      EJB Exception: : java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.
      at weblogic.deployment.BasePersistenceContextProxyImpl.validateInvocation(BasePersistenceContextProxyImpl.java:110)
      at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:86)
      at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:89)
      at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:80)
      at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:24)
      at $Proxy83.getTransaction(Unknown Source)
      Thanks
        • 1. Re: Ejb exception
          René van Wijk
          When using JTA you have to use UserTransaction.

          You can obtain an instance of UserTransaction by using EJBContext, for example,
          @Resource
          EJBContext context
          
          public void doeSomethingUseful() {
              context.getUserTransaction().begin(); // begins a transaction
          }
          Or you can use the annotation TransactionAttribute, for example,
          @PersistenceContext(unitName="example")
          EntityManager entityManager;
          
          @Transaction(TransactionAttributeType.REQUIRED)
          public void addSomething(Something something) {
              entityManager.persis(something);
          }