5 Replies Latest reply on Mar 5, 2013 1:06 PM by Adar Dembo

    Expected behavior when traversing deleted relations that are targetAuditMode=RelationTargetAuditMode.NOT_AUDITED

    Adar Dembo Newbie


      I'm evaluating Envers for historical configuration tracking in our system. So far I really like what I see; our custom history mechanism is many lines of complex code, and Envers has the potential to get rid of that.


      One thing I'm stumbling on is Envers' behavior involving deletions and NOT_AUDITED. Here's a sample data model:



      class Foo {


        String interestingField;



        Bar myBar;


        public boolean equals(Object obj) {

          // compares interestingField and myBar



        public int hashCode() {

          // hashes interestingField and myBar





      class Bar {





      Now imagine the following:

      1. Transaction 1 creates and persists a Foo and a Bar.
      2. Transaction 2 deletes both the Foo and the Bar.
      3. Transaction 3 queries for all revisions.

      What I'm seeing is that the query throws an exception that looks kind of like this:



      javax.persistence.EntityNotFoundException: Unable to find Bar with id 1

                at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:155)

                at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:171)

                at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:160)

                at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)

                at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)


                at org.hibernate.envers.tools.Triple.hashCode(Triple.java:74)

                at java.util.HashMap.put(HashMap.java:372)

                at org.hibernate.envers.reader.FirstLevelCache.putOnEntityNameCache(FirstLevelCache.java:87)

                at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:104)

                at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:134)

                at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:105)




      I was expecting to get back two revisions. In the first, I was expecting a Foo associated to null (since the "current" Bar was deleted). At the very least, it'd be nice to avoid initializing Bar's proxy within Envers; let me step on (or avoid) that landmine myself.