Announcement Announcement Module
No announcement yet.
Using Envers in a Spring Roo project Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Envers in a Spring Roo project

    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 am using Tomcat as the Application Server and have not added any specific configuration for Envers.

    I have:

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

    2. The file consists of the following:

    3. The persistence.xml contains the following:

        <property name="" 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:

    Section 15.1 Basics states that if hibernate-envers.jar is used, @Audited is added to an entity and 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;
        @Column(name = "version")
        private Integer Contract.version;
        public Long Contract.getId() {
        public void Contract.setId(Long 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 class (See above) even though it doesn't have the @Entity annotation.

    Any advise you could offer would be appreciated.

    Many thanks in advance

    Last edited by pts8; Nov 20th, 2012, 12:00 PM.