0 Replies Latest reply on Jun 6, 2017 2:53 PM by 937062

    Help needed - Persist 2 entities

    937062

      Hi All,

       

      Am new to EJB and trying the below scenario.

      Below is my use case and am facing difficulty in accomplishing this.

      i need to persist some data for an entity and using the data from this entity i need to persist data into a history table (insert a new row for each column present in my first entity).

      Am trying to persist 2 entities in a single transaction, below is the flow that am using.

       

      in bean1:

      @EJB

      bean2 da;

       

      method1(object)

      {

      em.persist(object);

      da.callhistorymethod(object)

      return object

      }

       

      in bean2:

      callhistorymethod(historyobject)

      {

      ---do somthing---

      em.persist(historyobject);

      }

       

      while running the process, it gives me the below error:

       

      java.lang.IllegalStateException: The transaction associated with this transaction-scoped persistence context has been rolled back and as a result,

      the EntityManager has been closed. No further operations are allowed in this transaction context. Please see the server log for the cause of the rollback.

       

      request you to help me with the above issue.