5 Replies Latest reply on Dec 2, 2010 9:36 AM by Gonzalo Ferreyra

    Envers is not auditing on a entity update

    Gonzalo Ferreyra Newbie

      Hello, we were using Hibernate 3.3 with Envers 1.1 successfully in a project until now, but we decided to migrate to Hibernate + Envers 3.5.1 and we are facing some troubles with it.

       

      For example, envers is not auditing any modifications when the DAO EJB merges the entity, but it works well with persist and remove.

       

      Here is the configuration in persistence.xml:

       

            <property name="hibernate.ejb.event.post-insert"
                      value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.post-update"
                      value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.post-delete"
                      value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,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" />
      

       

      And this is one of the entities which is suffering this problem:

       

      @Entity
      @Table(name = "termino_tesauro",
          uniqueConstraints={@UniqueConstraint(columnNames="termino")})
      @Audited
      @AuditTable(schema="auditoria", value="termino_tesauro_auditoria")
      public class TerminoTesauro implements Serializable {
          
          public static final String CRITERIO_BUSQUEDA_TERMINO = "termino";
      
          @Id
          @Column(name = "id", nullable = false)
          @GeneratedValue(generator="palabra_tesaurus_seq")
          @SequenceGenerator(name="palabra_tesaurus_seq", 
                  sequenceName="palabra_tesaurus_id_seq")
          private Long id;
      
          @Column(name="termino")
          private String termino;
      
          @Column(name="definicion")
          private String definicion;
      
      //getters, setters, constructors and others methods..
      }
      

       

      We've read the documentation files, but we are out of ideas about what is wrong. Looking at the generated sql, hibernate it's not trying to insert any audit inserts when merges the entity, but it merges well the entity (generating the correct insert in the 'auditoria' schema).

       

      Thanks in advance

       

      Gonzalo Ferreyra

        • 1. Re: Envers is not auditing on a entity update
          Hernán Chanfreau Master

          Hi!

           

          Did you try the last 3.5 release?

          I think there were some problems related to this on first 3.5 releases...

           

          Regards. Hernán.

          • 2. Re: Envers is not auditing on a entity update
            Adam Warski Master

            Yes, Hernan is correct, please use the latest Envers version from the 3.5 branch - 3.5.6.

             

            Adam

            • 3. Re: Envers is not auditing on a entity update
              Gonzalo Ferreyra Newbie

              Thanks Adam and Hernan, I did it and this situation was corrected; but now are appearing some new troubles (which may have been present with 3.5.1 final, but we didn't go this far, because we were focused on the others bigger troubles); the OneToMany relationships are not being audited at all......

              An example of this situation is:

               

               

              @Entity
              @Table(name = "servicio",
              uniqueConstraints =
              @UniqueConstraint(columnNames = {"numero_proyecto"}))
              @Audited
              @AuditTable(schema = "auditoria", value = "servicio_auditoria")
              public class Servicio implements Serializable {
              
                  @Version
                  @Column(name = "version")
                  int version;
                  @Id
                  @Column(name = "id", nullable = false)
                  @GeneratedValue(generator = "servicio_seq")
                  @SequenceGenerator(name = "servicio_seq",
                  sequenceName = "servicio_id_seq")
                  private Long id;
              
              // some fields......
              
                  @OneToMany(mappedBy = "servicio", cascade = {CascadeType.REMOVE})
                  private List<Prestacion> prestaciones;
              
              // others fields, methods, etc}
              
              
              @Entity
              @Table(name="prestacion")
              @Audited
              @AuditTable(schema="auditoria", value="prestacion_auditoria")
              public class Prestacion implements Serializable {
              
                  @Id
                  @GeneratedValue(strategy = GenerationType.AUTO)
                  private Long id;
              
                  @Column(name="nombre", nullable=false)
                  private String nombre;
              
                  @Column(name="descripcion", nullable=false)
                  private String descripcion;
              
                  @Column(name="codigo", nullable=true)
                  private String codigo;
              
                  @Column(name="precio_minimo", nullable=true)
                  private BigDecimal precioMinimo;
              
                  @Column(name="precio_maximo", nullable=true)
                  private BigDecimal precioMaximo;
              
                  @ManyToOne
                  @JoinColumn(name="servicio_id", nullable=false)
                  private Servicio servicio;
              
                  //constructors, other methods, etc
              }
              

               

              In the "auditoria" schema, there are not being audited any operations about the "Prestacion" entity, neither persist, merge, nor remove....

               

              We replaced the collection from List<Prestacion> to Set<Prestacion> following the examples in the documentation, but the behavior was the same.... I will try with @AuditTable for the relationship, but I think the problem is with the instances, and not with the relationship.

               

              Thanks again

               

              Gonzalo

              • 4. Re: Envers is not auditing on a entity update
                Adam Warski Master

                And does it work if you place all tables in the same schema?

                 

                Adam

                • 5. Re: Envers is not auditing on a entity update
                  Gonzalo Ferreyra Newbie

                  Hello Hernán, Adam, we had some configurations problems, but migrating from Hibernate 3.5.1 to 3.5.6 fixed all the troubles. Thanks a lot for the support.

                  Gonzalo