4 Replies Latest reply on Jun 24, 2009 8:13 AM by The empi

    Forcing Envers to commit changes with Seam

    The empi Newbie

      Hey there,

      I'm struggling to get envers to commit the new entries into the DB right after my entities have been persisted.

      I have a SLSB which acts as a Dao containing the following Methods:

      @AutoCreate
      @Stateless
      @Name("bGenericDao")
      public class GenericDaoImpl implements GenericDao {
       @PersistenceContext
       private EntityManager em;
      
       ...
       public void save(Object pObj) {
       em.persist(pObj);
       }
      
       public void saveAlternative(Object pObj) {
       Session lS = (Session) em.getDelegate();
       lS.setFlushMode(FlushMode.COMMIT);
       Transaction lTrans = lS.beginTransaction();
       lTrans.begin();
       getManager().persist(pObj);
       lTrans.commit();
       }
       ...
      }
      


      What happens is that the changes to my Entity are flushed correctly, But entries into the RevisionTables are written when my Test has reached the End.

      lSomePersistedEntity.setName("NameChanged");
      
      bGenericDao.save(lSomePersistedEntity);
       // or saveAlternative()
      
      AuditReader lAuditReader = AuditReaderFactory.get(getManager());
      AuditQuery lRevisions = AuditReader.createQuery()
       .forRevisionsOfEntity(lSomePersistedEntity.class, true, false);
      
      int lSize = lRevisions.getResultList().size();
      // lSize is 0
      


      Hibernate output

      ...
      Hibernate: update SomeEntity set ...
      Hibernate: select SomeEntity_.mId as mId19_, someentity0_.REV as REV19_, ...
      Hibernate: insert into EntityRevisions (mId, mTimestamp) values (null, ?)
      Hibernate: call identity()
      Hibernate: insert into SomeEntity_AUD (REVTYPE, ...
      ...


      Can you give me any hint howto tell Envers to write the revisionentries immediately?

      Best Regards
      empi

      seam: 2.1.1.GA
      hibernate: 3.3.0.SP1
      Envers: 1.2.1.GA (for hibernate 3.3)