2 Replies Latest reply on Nov 21, 2012 2:36 PM by Adam Warski

    Using Envers in a Spring Roo project

    pts8 Newbie

      Hi all,


      I have created a Spring Roo project using a MySQL DB and am trying to get Envers working to audit changes to the entities. At the moment, the projects entities are being created in the DB (with a version field in each of the tables) but no envers audit tables are being created.


      I have:


      1. Included hibernate-envers.4.1.7.Final and its associated dependencies into the projects pom file.


      2. The database.properties file consists of the following:







      3. The persistence.xml contains the following:


      <property name="hibernate.hbm2ddl.auto" value="create"/>

      <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>

      <property name="hibernate.connection.charSet" value="UTF-8"/>


      4. An example entity is as follows:









      @RooJpaActiveRecord(finders = { "findContractsByNameEquals" })


      public class Contract {



          @Size(min=3, max=3)

          private String abbreviation;



          @Size(max = 10)

          private String reference;



          @Column(unique = true)

          @Size(max = 25)

          private String name;


          @OneToMany(cascade = CascadeType.ALL, mappedBy = "contract")

          private Set<Proposal> proposals = new HashSet<Proposal>();


          @OneToMany(cascade = CascadeType.ALL, mappedBy = "contract")

          private Set<Task> tasks = new HashSet<Task>();



      Envers documentation: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch15.html


      Section 15.1 Basics states that if hibernate-envers.jar is used, @Audited is added to an entity and hibernate.hbm2ddl.auto option is set to create, create-drop or update then audit tables will be created. This is not happening.


      Other Envers examples I have seen have placed the @Audited annotation after the @Entity annotation. In Spring Roo, the @Entity is actually used in a Roo generated file which you dont change:




      privileged aspect Contract_Roo_Jpa_Entity {


          declare @type: Contract: @Entity;



          @GeneratedValue(strategy = GenerationType.AUTO)

          @Column(name = "id")

          private Long Contract.id;



          @Column(name = "version")

          private Integer Contract.version;


          public Long Contract.getId() {

              return this.id;



          public void Contract.setId(Long id) {

              this.id = id;



          public Integer Contract.getVersion() {

              return this.version;



          public void Contract.setVersion(Integer version) {

              this.version = version;





      As a result, I added the @Audited annotation to the Contract.java class (See above) even though it doesn't have the @Entity annotation.


      Any advise you could offer would be appreciated.


      Many thanks in advance