2 Replies Latest reply on Aug 11, 2008 3:52 PM by Adrien Orsier

    EntityManager not persisting with no error inside an asynchronous call

    Adrien Orsier Newbie

      Hi,


      I have a curious problem using the SMPC.
      I think it's due to the fact I have a transaction which is not commited, see below:



      @Asynchronous
      public void runAsynchronous() {
           run();
      }




      @Transactional
      @TransactionTimeout(9000000)
      private Event run() {
        Event event = new Event();
        entityManager.persist(event)
      }



      Basically, entityManager isn't persisted anything, but I have no error message.


      I tryed to do:


      Session session = (Session)entityManager.getDelegate();
      session.persist(event);
      session.flush();



      And it worked, though if I launch this action two times in a row, I got a concurrent modification exception : couldn't commit transaction, so I don't think this is the proper solution.





        • 1. Re: EntityManager not persisting with no error inside an asynchronous call
          System Administrator Expert
          Since you're using @Transactional, you're not using EJB3 (SLSB/SFSB).

          If you were to convert this JavaBean to a SFSB, for example, the PersistenceContext would be flushed by the EntityManager/container after the persist() method execution.

          Not sure how it works with @Transactional and JavaBeans.

          When using SMPC, I know you can set the |flushModeType=MANUAL| and flush the PersistenceContext yourself.  I'm not sure if this will work or not with JavaBeans, however.  This is obviously similar to what you're doing above with session.flush().

          You're not calling any setter methods on the event entity instance... I'm assuming your table does not have any not null columns (except maybe for the identity column)?

          Does your code work if you convert to EJB3??

          Here is an example using a JavaBean with Hibernate from the hibernate Seam example:
          @Factory
          @Observer("bookingConfirmed")
          @Transactional
          public void getBookings()
          {
                bookings = bookingDatabase.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate")
                      .setParameter("username", user.getUsername())
                      .list();
          }
          • 2. Re: EntityManager not persisting with no error inside an asynchronous call
            Adrien Orsier Newbie

            At the moment we're using a simple POJO to do the job.
            I think manual flush won't work, since when I called entityManager.flush before using the session, it would end up doing an exception (not possible to flush).