1 Reply Latest reply on Sep 18, 2007 9:00 AM by homer homer

    EntityManager.persist() not being rolledback

    homer homer Newbie

      Jbo 4.2/Hibernate 3

      Pretty much following the Transaction demo in Trailblazer demo:

      This sample shows rolling back an update transaction which works fine for me. The problem is that if my session bean is adding a new record it does not roll back when I throw a TransException.

      In the code sample below "rec" is updated and "rec2" is a new record. I try to force a rollback by throwing a TransException. The rec update is rolled back but the new row (from rec2) is still persisted:

      OutboundQueue rec = em.find(OutboundQueue.class, Integer.valueOf(1503));
       rec.setMessage("This message has been updated:" + new Date());
       OutboundQueue rec2 = new OutboundQueue();
       if (rec != null)
       throw new TransException();

      Here is my EntityManager def:
      @PersistenceContext(type = PersistenceContextType.TRANSACTION)
       protected EntityManager em;

      I am including the following annotation on my method:

      I've noticed that the flush mode on em is AUTO. I tried setting it to COMMIT via:


      ... but it had no affect.

      Any idea what might be wring here?