1 Reply Latest reply on Mar 6, 2008 8:01 AM by jaikiran

    em.persist(entity) ignores transaction

    javatwo

      Hi,

      I am using JBoss 4.0.5GA and mysql 5.0 database.


      in web tier:

      UserTransaction userTransaction =
      (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
      
      userTransaction.begin();
      
      
      // in session bean, em is EntityManager
      em.persist(entity);

      From mysql console, the entity was created immediately in database(mysql).

      I expected it to be created after calling

      userTransaction.commit();

      in web tier.


      For debugging, I added the following code around em.persist(entity):

      //debug
      Session session = ((HibernateSession)em).getHibernateSession();
      Transaction t = session.getTransaction();
      
      t.begin();
      
      em.persist(entity); // the enitty was created immediately in database (see from mysql console)
      
      t.rollback();
      
      boolean committed = t.wasCommitted(); // value is false
      boolean rollback = t.wasRolledBack(); // value is false

      after the rollback, the created entity did not roll back. The transaction was ignored.

      Is this a bug? How to use UserTransaction with entityManager?

      Thanks for any help!
      Dave