1 Reply Latest reply on Nov 8, 2014 7:23 AM by mpanev

    @Audited on a subclass... again

    mpanev

      Hi guys,

       

      I know this has been asked a thousand times, but I've also tried a thousand solutions and it keeps not working...

      I have a classic situaton with entities A, B and C, which inherit from each other in that order (C extends B, B extends A). Class B is abstract - in case that matters, while A and C are not. I want to audit C. Entities B and C are under my control, entity A is not - it is included from a .jar and I have no access to the source code. Besides, it has many other subclasses which need not be audited. The inheritance strategy on the whole hierarchy is SINGLE_TABLE. This is actually suboptimal, but I can't change it, since it is set on A, so I have to live with that.

       

      So I have annotated B and C with @Audited and B additionally with @AuditOverride(forClass = A.class). I can annotate C with that, too, if that's needed (my understanding is that it is not). What I get is

       

      ...

      Caused by: org.hibernate.MappingException: Entity 'B' is audited, but its superclass: 'A' is not.

      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateInheritanceMappingData(AuditMetadataGenerator.java:365)

      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:431)

      at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:101)

      at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:103)

      at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:135)

      at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:63)

      at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)

      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)

      at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)

      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)

       

      So the simple question is how do I correct that and what am I doing wrong? I have also tried using the deprecated @Audited(auditParents=...), but that doesn't work either. So it must be some other issue...

      Oh, and I am using Hibernate/Envers 4.2.9 since we are on a JBoss 7 and need JPA 2.0. Below is a dump of all involved classes with all annotatons on them.

       

      Thanks for any suggestions!

      Mike

       

       

      @Entity

      @Table(name = "A")

      @DynamicUpdate

      @OptimisticLocking(type = OptimisticLockType.VERSION)

      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)

      public class A {

      ...

      }

       

      @Entity

      @DiscriminatorValue(value = "b")

      @Access(AccessType.FIELD)

      @Audited

      @AuditOverride(forClass = A.class)

      public abstract class B extends A {

      ...

      }

       

      @Entity

      @DiscriminatorValue(value = "c")

      @Access(AccessType.FIELD)

      @Audited

      public class C extends B {

      ...

      }

        • 1. Re: @Audited on a subclass... again
          mpanev

          I now tried a minimalistic testcase - superclass not audited, subclass audited and overrite of superclass:

           

          @Entity

          public class TestSuperEntity {

              @Id

              private long id;

              private String someString;

          }

           

          @Entity

          @Audited

          @AuditOverride(forClass = TestSuperEntity.class)

          public class TestSubEntity extends TestSuperEntity {

              private int someInt;

          }

           

          This fails with a MappingException at schema generation. Any idea what I may be doing wrong?

           

          Thanks,

          Mike