2 Replies Latest reply on Jul 6, 2011 4:35 AM by Adam Warski

    Envers with Custom Reverse Engineering Strategy

    Adam Retter Newbie

      So I am using a custom reverse engineering strategy (by extending org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy) with Hibernate Tools to generate my Java Hibernate ORM classes from my Postgres database Schema.


      I now want to start using Envers, but I cannot understand how to have my custom reverse engineering strategy or Hibernate tools add the Envers @Audited annotations to my classes.


      Any ideas?



      My Maven config to invoke Hibernate Tools looks like this -






































        • 1. Re: Envers with Custom Reverse Engineering Strategy
          Adam Retter Newbie

          So I managed to do pretty much this by overriding the methods columnToMetaAttributes(...) and tableToMetaAttributes(...). By manipulating the CLASS_SCOPE or GET_SCOPE you can inject your annotations for envers.


          However I cannot seem to inject Annotations on get'ers which are mappings to foreign keys, so for example on my ServiceUser Entity (audited), there is a foreign key from Booking Entity (not-audited) -


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

              public Set<Booking> getBookings() {

                  return this.bookings;



          Now I need to be able to add the @NotAudited annotation to the method, but this does not seem possible through a custom reverse engineering startegy. I did look into the code and it should be possible to add some support for adding in custom annotations in a clean way, but this is way deeper than I want to go. So for the time being I have abandoned reverse engineering strategy.

          • 2. Re: Envers with Custom Reverse Engineering Strategy
            Adam Warski Master

            I've never tried this, but maybe you can also post on the Hibernate/JBoss Tools forum, with a feature request to be able to add custom annotations more easily.