6 Replies Latest reply on May 27, 2010 11:02 AM by rodrigors

    Envers + Maven + Seam + JBoss5: AUD_ tables created, but no auditing

    rodrigors

      Hi,

       

      I've setup Envers 1.2.2-hibernate-3.3 with Seam 2.2. The project builds nicely with Maven (pom below), the envers jar is bundled into the lib folder of the .EAR that is deployed to JBoss5 (tried 5.1 too).

       

      The problem is: during the application startup, the auditing tables and entities (prefixed AUD) are created by Hibernate. When I run the application and create, edit or delete entities only the entities are changed. No auditing, no versioning in REVINFO.

       

      I have three things in mind:

       

      1. for some reason, the Envers listeners are not triggered by Hibernate events (I will check if default EJB3 triggers are).

      2. some transaction configuration is not compatible with Envers. I am using a Seam Managed Persistent Context with JTA transactions (the project was created with seam-gen).

      3. some dependency conflict or other library is overriding the Envers listeners.

       

      I'd appreciate if someone could help me. I've been with this issue around for almost a week.

       

      Rodrigo

       

      --- persistence.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0"
          xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
              http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      
          <persistence-unit name="${app.persistence.unit.name}"
              transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>${app.jta.data.source}</jta-data-source>
              <properties>
                  <property name="jboss.entity.manager.factory.jndi.name"
                      value="${app.persistence.unit.jndi.name}" />
      
                  <property name="hibernate.dialect" value="${ds.hibernate.dialect}" />
                  <property name="hibernate.hbm2ddl.auto" value="create-drop" /><!--  ${env.hibernate.hbm2ddl.auto} -->
                  <property name="hibernate.show_sql" value="true" /><!-- ${env.hibernate.show_sql} -->
                  <property name="hibernate.format_sql" value="true" /><!-- ${env.hibernate.format_sql} -->
                  <!--
                      <property name="hibernate.default_catalog"
                      value="${ds.database.name}"/>
                  -->
      
                  <property name="hibernate.default_batch_fetch_size" value="${env.hibernate.default_batch_size}" />
      
                  <!-- Encoding -->
                  <property name="hibernate.connection.useUnicode" value="true" />
                  <property name="hibernate.connection.characterEncoding"
                      value="UTF-8" />
      
                  <!-- These are the default for JBoss EJB3, but not for HEM: -->
                  <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /><!-- Hashtable -->
                  <property name="hibernate.transaction.manager_lookup_class"
                      value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                      
                  <!-- Precisa adicionar essa linha para rodar no JBoss 5.1.0 -->
                  <property name="jboss.entity.manager.factory.jndi.name"
                      value="java:/entityManagerFactory" /> 
                      
      
                  <!-- Listeners required by envers -->
                  <property name="hibernate.ejb.event.post-insert"
                      value="org.hibernate.envers.event.AuditEventListener" />
                  <property name="hibernate.ejb.event.post-update"
                      value="org.hibernate.envers.event.AuditEventListener" />
                  <property name="hibernate.ejb.event.post-delete"
                      value="org.hibernate.envers.event.AuditEventListener" />
                  <property name="hibernate.ejb.event.pre-collection-update"
                      value="org.hibernate.envers.event.AuditEventListener" />
                  <property name="hibernate.ejb.event.pre-collection-remove"
                      value="org.hibernate.envers.event.AuditEventListener" />
                  <property name="hibernate.ejb.event.post-collection-recreate"
                      value="org.hibernate.envers.event.AuditEventListener" />
                      <!-- org.hibernate.ejb.event.EJB3PostInsertEventListener, -->
                      
                  <property name="org.hibernate.envers.audit_table_prefix" value="AUD_"/>
                  <property name="org.hibernate.envers.audit_table_suffix" value=""/>
                    <property name="org.hibernate.envers.revision_on_collection_change" value="false" />
                    
              </properties>
          </persistence-unit>
      
      </persistence>
      

       

      --- simple class example:

       

      package com.company
      // Generated 22/02/2010 17:13:13 by Hibernate Tools 3.2.2.GA
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.Table;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.hibernate.envers.Audited;
      
      /**
       * Anbid generated by hbm2java
       */
      @Entity
      @Audited
      @Table(name = "ANBID")
      public class Anbid implements java.io.Serializable {
      
          private long id;
          private PessoaJuridica pessoaJuridica;
          private String anbid;
      
          public Anbid() {
          }
      
          public Anbid(long id, PessoaJuridica pessoaJuridica, String anbid) {
              this.id = id;
              this.pessoaJuridica = pessoaJuridica;
              this.anbid = anbid;
          }
      
          @Id
          @Column(name = "ID", unique = true, nullable = false)
          public long getId() {
              return this.id;
          }
      
          public void setId(long id) {
              this.id = id;
          }
          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "FUNDO_ID", nullable = false)
          @NotNull
          public PessoaJuridica getPessoaJuridica() {
              return this.pessoaJuridica;
          }
      
          public void setPessoaJuridica(PessoaJuridica pessoaJuridica) {
              this.pessoaJuridica = pessoaJuridica;
          }
      
          @Column(name = "ANBID", nullable = false, length = 6)
          @NotNull
          @Length(max = 6)
          public String getAnbid() {
              return this.anbid;
          }
      
          public void setAnbid(String anbid) {
              this.anbid = anbid;
          }
      
      }
      

       

      --- the root pom.xml is attached. Envers is delcared as a dependency in ejb/pom.xml (i'm using an ejb/ear/war project module design).