5 Replies Latest reply on Jan 6, 2012 1:41 AM by a a

    How do I use Envers with custom session factory?

    a a Newbie

      Hi,

       

      We are using spring-hibernate.

      Hibernate version - 3.5.1

      Spring version - 3.0

       

      Envers - 3.5.6-Final

       

      I want to explore Envers for auditing the entities defined by us and have defined our own session factory bean which overrides AnnotationSessionFactoryBean.



      My session factory is created with spring using "AnnotationSessionFactoryBean". It is configured as follows:

       

      <bean id="factory" class="com.test.mappingmanager.hibernate.MySessionFactory.MySessionFactory">

                  <property name="jtaTransactionManager">

                  <bean factory-bean="txManagerJta" factory-method="getTransactionManager"/>

              </property>

       

       

              <property name="dataSource" ref="dataSource"/>

              <property name="mappingManager" ref="MappingModifier"/>

              <property name="mappingLocations">

                  <list>

                      <value>classpath*:com/test/**/*.hbm.xml</value>

                  </list>

                    </property>

       

                <property name="annotatedClasses">

                          <bean class="com.test.mappingmanager.hibernate.common.EntityBeanFinderFactoryBean">

                                    <property name="searchPatterns">

                                              <set>

                                                        <value>classpath*:com/test/**/**/pojo/*.class</value>

                                               </set>

                                    </property>

                          </bean>

                </property>

                    <property name="hibernateProperties">

                  <props>

                      <prop key="hibernate.dialect">#{dbProperties['hibernate.dialect']}</prop>

                      <prop key="hibernate.show_sql">#{dbProperties['show_sql']}</prop>

                      <prop key="hibernate.jdbc.use_streams_for_binary">#{dbProperties['hibernate.jdbc.use_streams_for_binary']}</prop>

                      <prop key="hibernate.connection.release_mode">after_statement</prop>

                      <prop key="hibernate.generate_statistics">true</prop>

                      <prop key="hibernate.current_session_context_class">jta</prop>

                      <prop key="hibernate.transaction.factory_class">#{dbProperties['hibernate.transaction.factory_class']}</prop>

                      <prop key="hibernate.transaction.manager_lookup_class">#{dbProperties['hibernate.transaction.manager_lookup_class']}</prop>

                       <prop key="hibernate.cache.use_second_level_cache">#{dbProperties['hibernate.cache.use_second_level_cache']}</prop>

                       <prop key="hibernate.cache.use_query_cache">#{dbProperties['hibernate.cache.use_query_cache']}</prop>

                       <prop key="hibernate.cache.provider_class">#{dbProperties['hibernate.cache.provider_class']}</prop>

                      <prop key="jta.UserTransaction">#{dbProperties['jta.UserTransaction']}</prop>

                  </props>

              </property>

      </bean>

       

      MySessionFactory extends AnnotationSessionFactoryBean.

       

      I defined following bean:

      <bean id ="enverseBean" class="org.hibernate.envers.event.AuditEventListener"></bean>

       

      and as soon as I add event listener by adding following lines to the above file and start server it goes in an infinite loop in LocalSessionFactoryBean.java and keeps on invoking setEventListeners method.

       

      <property name="eventListeners">

                     <map>

               <entry key="post-insert" value-ref="enverseBean" />

               <entry key="post-update" value-ref="enverseBean" />

               <entry key="post-delete" value-ref="enverseBean" />

               <entry key="pre-collection-update" value-ref="enverseBean" />

               <entry key="pre-collection-remove" value-ref="enverseBean" />

               <entry key="post-collection-recreate" value-ref="enverseBean" />

                     </map>

      </property>

       

       

      Could you please let me know how do I use/configure Envers with custom session factory?

       

      Thanks.