Envers FAQ

Version 15

    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 Developer guide, for Hibernate 4.0 see: http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch15.html


    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-4/3.6 compatible versions, you should use the new group and artifact ids. Use this 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:








    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



    How to enable/disable auditing at runtime?

    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