我正在开发一个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
注释。
提前谢谢。
答案 0 :(得分:0)
想出来但不能早点回答。从那时起就更好了:-)。
我们必须使用<tx:annotation-driven>
。
另外我认为Spring的事务管理和Hibernate模板的saveOrUpdate存在一些问题。当一起使用时,saveOrUpdate抛出nonUniqueKey异常,但合并工作正常。