4 Replies Latest reply on Apr 11, 2013 9:25 AM by stigrv

    RelationTargetAuditMode.NOT_AUDITED to Audited entity

    peter.eigenschink

      I have two entities, A and B, both of them audited. A has a bidirectional OneToMany-Relation to B. When I call getA() on B I want to get the latest A from the A table (not A_AUD), so I annotate getA() with "@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)".

      In code(-snippets):

       

      // Entity A

      @OneToMany(mappedBy = "b", fetch = FetchType.LAZY)

      public List<B> getB() {

           return b;

      }

       

      // Entity B

      @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)

      @ManyToOne(fetch = FetchType.LAZY)

      public A getA() {

           return a;

      }

       

      But what I now actually get when I call getA() is the A out of A_AUD at the given revision.

      Is there a way to get the most recent version of A out of the actual table?

       

      Regards

      Peter

        • 1. Re: RelationTargetAuditMode.NOT_AUDITED to Audited entity
          adamw

          RelationTargetAuditMode.NOT_AUDITED works only if A isn't audited - it sounds as it is.

          If A is audited you need to look it up yourself using the entity manager.

           

          Adam

          • 2. Re: RelationTargetAuditMode.NOT_AUDITED to Audited entity
            peter.eigenschink

            Maybe it's just my opinion, but shouldn't the explicit specification of RelationTargetAuditMode.NOT_AUDITED overrule the specification of A as audited from B's point of view?

            Sure you are right, that it sounds as it is, but I think, as nobody would mark a relationship which should be audited with this annotation, it would be nice if it was possible to specify a relationship to an audited entity as RelationTargetAuditMode.NOT_AUDITED to point to the most recent version of this entity.

             

            Peter

            • 3. Re: RelationTargetAuditMode.NOT_AUDITED to Audited entity
              adamw

              Hmm well I think that in fact in such a case an exception should be thrown. Wanting to get the latest version of an entity on an audited relation seems like a very rare use-case.

               

              Adam

              • 4. Re: RelationTargetAuditMode.NOT_AUDITED to Audited entity
                stigrv

                I have to agree with Peter here. There are some rare cases where you actually need this annotation to work in this way. I ran into the same issue myself now, and has been scratching my head for a few hours trying to figure out what I did wrong.

                 

                I also checked the envers source code to see where this annotation is read. The only place it is read, as far as I can see, is to avoid an error message if you link to an un-audited entity. It might therefore be a bit more involved in solving this problem.