5 Replies Latest reply on Nov 8, 2011 5:38 PM by Chetan M

    Envers with Hibernate Sessions and Spring

    Chetan M Newbie

      Hi,

       

      I have followed the quickstart guide and I have see Envers work.Now I'm trying to use the same in our project here.

      The project uses Hibernate with Spring and plain jdbc transactions (by way of session.getTransaction())..

      Ideally,I expect to see the audit happening on tx.commit() however it isn't happening.

      I'm not sure where to look for since there are no errors or anything of that sort.Apart from the audit everything seems to be happening as it was.Just that the listeners and the @Audited annotation seem to have no effect (adverse/beneficial).

       

      Can you please let me know how to go about this situation.

      I'm sorry I don't even know what other details I can provide so that I can request help from others on the forum here.

      Any help is appreciated.

       

      Regards

      Chetan

        • 1. Re: Envers with Hibernate Sessions and Spring
          Chetan M Newbie

          A little more details.I changed my spring configuration to add the required listeners (corressponding to setEventListeners) on the

          org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.

          Read on the internet that the listeners have to go under listeners property and not hibernateProperties.

          Now while debugging I find that AuditListener code gets invoked but there are no rows being created.I'm using hbm.dd.auto="update" so I see the tables created too but witout any rows and without any exceptions.

          Can someone point me in the right direction.

          Regards,

          Chetan

          • 2. Re: Envers with Hibernate Sessions and Spring
            Adam Warski Master

            It must be something with the transactions configuration. Are you using MySQL? If so, do you have autocommit off and are you using InnoDB?

             

            Adam

            • 3. Re: Envers with Hibernate Sessions and Spring
              Chetan M Newbie

              Thanks for the quick reply.We use Oracle.

              By the way I even went into the config and since we use org.apache.commons.dbcp.BasicDataSource i specifically added the defaultAutoCommit=false

              <bean id="referenceDataSource" class="org.apache.commons.dbcp.BasicDataSource"

              destroy-method="close" lazy-init="true">

              <property name="driverClassName" value="oracle.jdbc.OracleDriver" />

              <property name="url" value="${dealworks.dw.database.url}" />

              <property name="username" value="${dealworks.dw.database.user}" />

              <property name="password" value="${dealworks.dw.database.password}" />

              <property name="defaultAutoCommit" value="false"/>

              </bean>

               

              I still don't see the audit happening.

              Also can you point me to the exact place/line where the actual insert happens for the audit records.

               

              Regards,

              Chetan

              • 4. Re: Envers with Hibernate Sessions and Spring
                Adam Warski Master

                Not sure which version you are using but can you try debugging AuditProcess.doBeforeTransactionCompletion/AuditSynchronization to see if the method is called and if the work units, which should write the audit, are executed.

                 

                Adam

                • 5. Re: Envers with Hibernate Sessions and Spring
                  Chetan M Newbie

                  Sure.will let you know.For now,after struggling to make Envers work with our existing code I finally ended up using spring transactions and it started to work.The hibernate callback that was being used had to be changed.

                  I will try and report my findings based on your above suggestion shortly though.

                   

                  Regards,

                  Chetan