4 Replies Latest reply on May 24, 2013 3:27 AM by chessray

    Partial auditing with MappedSuperclasses

    chessray

      Hi everyone,

       

      We're taking our first steps in auditing with Envers, but seem to have hit a dead end.

       

      Here's the basic situation: All our entities consist of two parts: one @MappedSuperclass (called <Entity>Base) which holds all properties including the relations (along with the appropriate JPA annotations) + getters and setters and the actual @Entity (class name <Entity>) which holds additional business methods. Why we're doing it this way? So that we can generate the base classes (along with other stuff that we need) out of a metamodel.

       

      Now we only want to audit some of the entities, but just can't get the relations to work out fine. What we've tried so far:

       

      1. a) Only annotating the actual entities with @Audited. Then Envers doesn't do anything.

          b) Adding the @AuditOverride annotations. Then Envers rejects the relations as these are pointing to the real entities (not the base classes) and some of them are not audited.

      2. a) Adding the @Audited annotations to the base classes along with @Audited(target=NOT_AUDITED) to the relations. Again, Envers is not really interested in this and just doesn't do anything.

          b) Adding @Audited and @AuditOverride to the real entities again. Then we have the same complaints about not audited entities in relations.

      3. Instead of annotating the attributes, we tried it with the methods so as to possibly override these in the real entity classes. This already upsets the JPA validation, as the attributes are of the real entity types and it claims the relationship's mappedBy-attribute is pointing to the wrong type.

       

      I've been bugging myself around with this for 3 days now, but just can't get it right. Maybe someone else has an idea. Right now, we've come to the conclusion that we have to rely on database triggers.

       

      We're using Jboss-as-7.1.1.Final with hibernate-core-4.0.1.Final and hibernate-envers-4.0.1.Final.

       

      Nachricht geändert durch Raimund Klein

        • 1. Re: Partial auditing with MappedSuperclasses
          adamw

          I think 1a) should work fine. Although ... the "real" entities don't have any audited properties?

           

          Adam    

          • 2. Re: Partial auditing with MappedSuperclasses
            chessray

            Hi Adam,

             

            Thanks for the response. As mentionend, we tried all of the above, but with no results. 1.a) just leads to Envers not doing anything - I tried with the Hibernate debug output on, and it definitely doesn't care about auditing at all (it doesn't even SELECT the sequence for the auditing entries).

             

            Like you say, the "real" entities don't have any audited properties of their own - or any properties at all, for that matter. All properties are inherited from the generated MappedSuperclasses. This setup's main intention is that we can keep the generated code fully apart from the manually developed parts. Plus, it's fitting quite well with our own application framework (which basically means that for us there's no way to rethink this whole thing in the current project state). It's working fine for everything - with the exception of employing envers for auditing.

             

            As I mentioned, we're open for suggestions. If you need more information to get down to the bottom, feel free to ask.

            • 3. Re: Partial auditing with MappedSuperclasses
              adamw

              I don't think there's anything with Envers that you can do currently ... that's kind of a bug (/feature request?) Can you report in JIRA?

               

              Adam

              1 of 1 people found this helpful
              • 4. Re: Partial auditing with MappedSuperclasses
                chessray

                Hi Adam,

                 

                Again thanks for looking into this. Here's the JIRA: https://hibernate.atlassian.net/browse/HHH-8268

                 

                I'll try to produce a minimum test case, but I'm not sure when I'll be able to do so.