Announcement Announcement Module
Collapse
No announcement yet.
Using Envers in a Spring Roo project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 database.properties file consists of the following:

    Code:
        database.driverClassName=com.mysql.jdbc.Driver
    
        database.url=jdbc\:mysql\://localhost\:3306/schema
    
        database.username=root
    
        database.password=
    3. The persistence.xml contains the following:

    Code:
        <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:

    Contract.java

    Code:
    @SuppressWarnings("serial")
    @RooJavaBean
    @RooToString
    @RooEquals
    @RooSerializable
    @RooJpaActiveRecord(finders = { "findContractsByNameEquals" })
    @Audited
    public class Contract {
    
        @NotNull
        @Size(min=3, max=3)
        private String abbreviation;
    
        @NotNull
        @Size(max = 10)
        private String reference;
    
        @NotNull
        @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/...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:

    Contract_Roo_Jpa_Entity.aj

    Code:
    privileged aspect Contract_Roo_Jpa_Entity {
    
        declare @type: Contract: @Entity;
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "id")
        private Long Contract.id;
    
        @Version
        @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

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