3 Replies Latest reply on Oct 12, 2011 5:16 AM by adamw

    Evers and legacy applications

    shadowlaw

      hi all,

       

      we have a legacy application using hibernate xml configuration and we would give a try to envers auditing.  Using envers with its default configuration works perfectly. But we need some customization to store data of the use who have done the changes to data in the DB. We created the persistence.xml file like this

       

      <persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">

                 <provider>org.hibernate.ejb.HibernatePersistence</provider>

                          <properties>

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

                                    <property name="hibernate.show_sql" value="true" />

                                    <property name="hibernate.format_sql" value="true" />

                                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

       

       

                                    <property name="hibernate.ejb.event.post-insert"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="hibernate.ejb.event.post-update"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="hibernate.ejb.event.post-delete"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="hibernate.ejb.event.pre-collection-update"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="hibernate.ejb.event.pre-collection-remove"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="hibernate.ejb.event.post-collection-recreate"

                                              value="com.axones.audit.lestener.HistoryEntityListener" />

                                    <property name="org.hibernate.envers.audit_table_suffix"

                                              value="_AUDITABLE" />

       

       

                                    <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>

       

       

                                    <property name="hibernate.bytecode.use_reflection_optimizer"

                                              value="false" />

                                    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />

                                    <property name="hibernate.connection.password" value="password" />

                                    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/mydb" />

                                    <property name="hibernate.connection.username" value="root" />

                                    <property name="hibernate.search.autoregister_listeners"

                                              value="false" />

       

                          </properties>

                </persistence-unit>

      and in hibernate.cfg.xml we keep the declaration of the entities either the xml configured or the annotation configured, but this does seem to work, envers stil using its default config revinfo, _aud tables.....

      how can i get the configuration so that envers uses the new listener and the new entity?

        • 1. Re: Evers and legacy applications
          adamw

          So one of the Hibernate entities has an @RevisionEntity annotation? The configuration looks correct. Are you sure the file gets copied to the deployment? If so, please try to breakpoint in the AuditEntitiesConfiguration class and see how the "org.hibernate.envers.audit_table_suffix" property is read.

           

          And btw. why do you have a subclass of the AduitEventListener?

           

          Adam

          • 2. Re: Evers and legacy applications
            shadowlaw

            ok, it seems that the listener was not registered, this is now corrected. i implemented the EventListener because, i want to store some meaningful data for us, what i want to do is to have the table i defined by the entity, in which i could store which entity was modified, which operation, the user and the time which wil help me in extracting some statistics reports

             

            thanks

            • 3. Re: Evers and legacy applications
              adamw

              For that purpose, I think you should use a custom revision entity and a revision listener, instead of subclassing the EventListener.

               

              Adam