2 Replies Latest reply on Jun 9, 2011 1:47 PM by Ernst-Udo Wallenborn

    How to find out whether audit recorded the current transaction?

    Ernst-Udo Wallenborn Newbie



      i use Envers in a project (Envers is great, btw) and have the following problem: there is a dao method that saveOrUpdates a certain audited entity. My service gets this entity passed in from outside and calls saveOrUpdate. Now i would like to find out if the update part of that actually changed something in the database. I could write a diff method, retrieve the entity from the database before and after i saveOrUpdate and use the diff to tell. But i think envers and hibernate are doing this for me already, anyway. Envers only writes an entry into the REVINFO table if and only if at least one insert, update or delete was performed on my entity. Which means that the revision entity will have an ID if and only if that happened. So i'd like to this:


      public void storeEntity(SomeEntity e) {

        RevisionEntity re = saveEntity(e);

        if (re.getId())

          log.info("Entity e changed, changed version was stored in database");


          log.info("RevisionEntity id is null");




      private RevisionEntity saveEntity(SomeEntity e) {

        dao.saveOrUpdate(entityManager, e);

        return AuditReaderFactory.get(entityManager).getCurrentRevision(RevisionEntity.class, false);



      So far, i can see that the RevisionEntity is created, it's written to the database, too, but the log only says "RevisionEntity id is null". Is this the expected behavior, or am i just doing it wrong?