Version 17

    This is a community-edited FAQ where you can describe the most common problems you encounter when using Envers and how to solve them. So feel free to edit this document!

     

    Where can I find Envers documentation?

    Envers documentation is now part of the Hibernate User guide, for Hibernate 5.x see: http://docs.jboss.org/hibernate/stable/orm/userguide/html_single/Hibernate_User_Guide.html#envers

     

    Using Envers with Maven

    Firstly you need to add the JBoss repositories either to your Maven settings, or to your pom.xml. See here for a description of how to do that.

     

    For the current, Hibernate-5/4/3.6 compatible versions, you should use the new group and artifact ids. Use this dependency:

     

    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-envers</artifactId>

        <version>5.2.8-Final</version>

    </dependency>

     

    <dependency>

       <groupId>org.hibernate</groupId>

       <artifactId>hibernate-envers</artifactId>

       <version>4.3.11-Final</version>

    </dependency>

     

    <dependency>

       <groupId>org.hibernate</groupId>

       <artifactId>hibernate-envers</artifactId>

       <version>3.6.10-Final</version>

    </dependency>

     

    (You'd want to match the version number with e.g. hibernate-core and hibernate-entitymanager)

     

    If you want to use the older, Hibernate-3.3 compatible versions, use the old group and artifact add this dependency to your pom.xml:

     

    <dependency>

       <groupId>org.jboss.envers</groupId>

       <artifactId>jboss-envers</artifactId>

       <version>1.2.2.GA-hibernate-3.3</version>

    </dependency>

     

    Filling in a revision entity with information obtained from Spring beans

    See this forum disucssion: http://community.jboss.org/message/4903#4903

     

    Problems with using Spring and Envers

     

    Dynamically configuring Envers using Spring

    http://sloanseaman.com/wordpress/2012/02/07/dynamic-configuration-of-hibernate-envers

     

    How to enable/disable auditing at runtime for versions 3.x/4.x?

    This is in fact quite easy and doesn't require any specific support on the Envers side. All you need to do is subclass the AuditEventListener class and override the methods that are called on Hibernate events: onPostInsert, onPostUpdate, onPostDelete, onPreUpdateCollection, onPreRemoveCollection and onPostRecreateCollection. There, you can check if the change should be audited (you have access to the name of the entity and the entity object itself) and if so, pass the call to the superclass. The only difference to normal Envers configuration is that you have to specify your class as the listener for the events.


    Grails + Envers

    See this discussion: http://www.nabble.com/Grails-1.1.1-%2B-Envers-1.2.1.GA-td25530411.html