数据未插入到 Spring-Hibernate-envers webapp 中的审计表中

发布于 2024-10-20 05:42:02 字数 3481 浏览 4 评论 0原文

我正在开发 Spring 和 Hibernate Web 应用程序。我必须使用 Envers 进行审计。
但是,当我运行应用程序时,仅创建审核表,但没有数据插入到审核表中。

配置文件:

<mvc:annotation-driven/>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>    
<bean name="callbackHandler" class="org.hibernate.ejb.event.EntityCallbackHandler" />
<bean name="auditEventListener" class="org.hibernate.envers.event.AuditEventListener" />
<bean name="ejb3PostInsertEventListener" class="org.hibernate.ejb.event.EJB3PostInsertEventListener">
  <property name="callbackHandler"><ref bean="callbackHandler"/></property>
</bean>
<bean name="ejb3PostUpdateEventListener" class="org.hibernate.ejb.event.EJB3PostUpdateEventListener">
  <property name="callbackHandler">
    <ref bean="callbackHandler" />
  </property>
</bean>
<bean name="ejb3PostDeleteEventListener" class="org.hibernate.ejb.event.EJB3PostDeleteEventListener">
  <property name="callbackHandler">
    <ref bean="callbackHandler" />
  </property>
</bean>
<bean id="sessionFactory" name="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
  lazy-init="false">
  <property name="dataSource" ref="dataSource" />
  <property name="annotatedClasses">
    <list>        
      <value>foo.bar.Person</value>
    </list>
  </property>

  <property name="hibernateProperties">
    <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
      <prop key="hibernate.show_sql">true</prop>
      <prop key="hibernate.max_fetch_depth">2</prop>
      <prop key="hibernate.default_batch_fetch_size">8</prop>
      <prop key="hibernate.jdbc.batch_size">20</prop>
      <prop key="hibernate.jdbc.batch_versioned_data">20</prop>
      <prop key="hibernate.generate_statistics">true</prop>
      <prop key="hibernate.jdbc.fetch_size">100</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
  </property>
  <property name="eventListeners">
    <map>
      <entry key="post-insert">
        <list>
          <ref bean="ejb3PostInsertEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="post-update">
        <list>
          <ref bean="ejb3PostUpdateEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="post-delete">
        <list>
          <ref bean="ejb3PostDeleteEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="pre-collection-update">
        <ref bean="auditEventListener" />
      </entry>
      <entry key="pre-collection-remove">
        <ref bean="auditEventListener" />
      </entry>
      <entry key="post-collection-recreate">
        <ref bean="auditEventListener" />
      </entry>
    </map>
  </property>   
</bean>

我在服务类中使用 @Transactional 注释。 提前致谢。

I am working on a Spring and Hibernate web app. I have to use Envers for auditing.
But when I am running the application only audit tables are created but no data is inserted to the audit tables.

Config file:

<mvc:annotation-driven/>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>    
<bean name="callbackHandler" class="org.hibernate.ejb.event.EntityCallbackHandler" />
<bean name="auditEventListener" class="org.hibernate.envers.event.AuditEventListener" />
<bean name="ejb3PostInsertEventListener" class="org.hibernate.ejb.event.EJB3PostInsertEventListener">
  <property name="callbackHandler"><ref bean="callbackHandler"/></property>
</bean>
<bean name="ejb3PostUpdateEventListener" class="org.hibernate.ejb.event.EJB3PostUpdateEventListener">
  <property name="callbackHandler">
    <ref bean="callbackHandler" />
  </property>
</bean>
<bean name="ejb3PostDeleteEventListener" class="org.hibernate.ejb.event.EJB3PostDeleteEventListener">
  <property name="callbackHandler">
    <ref bean="callbackHandler" />
  </property>
</bean>
<bean id="sessionFactory" name="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
  lazy-init="false">
  <property name="dataSource" ref="dataSource" />
  <property name="annotatedClasses">
    <list>        
      <value>foo.bar.Person</value>
    </list>
  </property>

  <property name="hibernateProperties">
    <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
      <prop key="hibernate.show_sql">true</prop>
      <prop key="hibernate.max_fetch_depth">2</prop>
      <prop key="hibernate.default_batch_fetch_size">8</prop>
      <prop key="hibernate.jdbc.batch_size">20</prop>
      <prop key="hibernate.jdbc.batch_versioned_data">20</prop>
      <prop key="hibernate.generate_statistics">true</prop>
      <prop key="hibernate.jdbc.fetch_size">100</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
  </property>
  <property name="eventListeners">
    <map>
      <entry key="post-insert">
        <list>
          <ref bean="ejb3PostInsertEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="post-update">
        <list>
          <ref bean="ejb3PostUpdateEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="post-delete">
        <list>
          <ref bean="ejb3PostDeleteEventListener" />
          <ref bean="auditEventListener" />
        </list>
      </entry>
      <entry key="pre-collection-update">
        <ref bean="auditEventListener" />
      </entry>
      <entry key="pre-collection-remove">
        <ref bean="auditEventListener" />
      </entry>
      <entry key="post-collection-recreate">
        <ref bean="auditEventListener" />
      </entry>
    </map>
  </property>   
</bean>

I am using @Transactional annotation in service classes.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够 2024-10-27 05:42:02

想通了,但无法提前回答。迟到总比不做好:-)。
为此,我们必须使用
另外我认为Spring的事务管理和Hibernate模板的saveOrUpdate存在一些问题。当一起使用时,saveOrUpdate 会抛出 nonUniqueKey 异常,但合并工作正常。

Figured it out but could not answer it earlier. Better late then never :-).
We have to use <tx:annotation-driven> for this.
Also I think there's some problem with Spring's transaction management and saveOrUpdate of Hibernate template. When used together, saveOrUpdate throws nonUniqueKey exception, but merge works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文