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

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 -

 

            <plugin>

                <groupId>org.codehaus.mojo</groupId>

                <artifactId>hibernate3-maven-plugin</artifactId>

                <version>2.2</version>

                <configuration>

                    <componentProperties>

                        <jdk5>true</jdk5>

                        <ejb3>true</ejb3>

                    </componentProperties>

                </configuration>

                <executions>

                    <execution>

                        <id>generate-hibernate-java</id>

                        <phase>generate-sources</phase>

                        <goals>

                            <goal>hbm2java</goal>

                        </goals>

                        <configuration>

                            <components>

                                <component>

                                    <name>hbm2java</name>

                                    <outputDirectory>target/generated-sources/hibernate3-classes</outputDirectory>

                                    <implementation>jdbcconfiguration</implementation>

                                </component>

                            </components>

                            <componentProperties>

                                <reversestrategy>uk.org.adamretter.hibernate.reveng.interfacestratergy.InterfaceReverseEngineeringStrategy</reversestrategy>

                                <packagename>uk.co.accountablecare.web.orm.generated</packagename>

                            </componentProperties>

                        </configuration>

                    </execution>

                </executions>

                <dependencies>

                   ...

                </dependencies>

            </plugin>

  • 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.

     

    Adam