2 Replies Latest reply on Nov 4, 2014 4:24 AM by tgrat

    Store entity in own WorkItemHandler

    tgrat

      Hello.

       

      We have own entity which we use to store data in database. We use below source code:

      Example 1
      UserTransaction ut = (UserTransaction) new InitialContext().lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
      ut.begin();
      EntityManager entityManager = Mediator.getInstance().getEntityManagerFactory().createEntityManager();
      ProcessIPOEntity processIPOEntity = entityManager.find(ProcessIPOEntity.class, ipoId);
      processIPOEntity.setProcessIpoConfNumber(procIPOId);
      entityManager.merge(entityManager);
      // -- commit
      ut.commit();

       

      If we use this source in main thread everything works correctly. But if we used it in our WorkItemHandler which extends AbstractLogOrThrowWorkItemHandler we had exception:

      Exception 1

      javax.transaction.NotSupportedException: nested transactions not supported

        at bitronix.tm.BitronixTransactionManager.begin(BitronixTransactionManager.java:120)

       

      Any advice how to solve this problem?

        • 1. Re: Store entity in own WorkItemHandler
          swiderski.maciej

          just remove transaction management (look up of UT and the begin and commit) from your code and it should work just fine. All operations done by the engine (executing work item handler) are done within transaction so there is no need to start another one. Creation of entity manager within active transaction makes it auto join that transaction - but you can always call entityManager.joinTransaction to ensure that.

           

          HTH

          • 2. Re: Store entity in own WorkItemHandler
            tgrat

            Thank you Maciej. It helps.

             

            We also had to move all updates of our entity to jbpm engine because there was a problem when we tried update entity from jbpm and from main thread which start jbpm process.

             

            Best regards,

            Tomek