asandrob 7 de nov. de 2012
Eu também tive um pouco de dificuldade, pelo que vi vc esta utilizando o Spring.
Eu não utilizo Spring e no meu hibernate.cfg.xml eu tive que fazer assim:
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "post-insert" / >
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "post-update" / >
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "post-delete" / >
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "pre-collection-update" / >
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "pre-collection-remove" / >
< listener class = "org.hibernate.envers.event.AuditEventListener" type = "post-collection-recreate" / >
fernandoat 8 de nov. de 2012
Asandrob obrigado pela resposta realmente não era o que estava procurando, mas mesmo depois de posta no forum continuei a procurar e vc me abriu um pouco a mente para procurar.
a solução foi incluir no sessionFactory a propriedade “eventListeners” e criar um bean do eventListener ficando assim
os itens em negrito foram as alterações.
<beans xmlns= "http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "http://www.springframework.org/schema/tx"
xsi:schemaLocation= "
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" >
//Incluido
<bean name= "auditEventListener" class= "org.hibernate.envers.event.AuditEventListener" />
//
<bean id= "sessionFactory" class= "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" destroy-method= "destroy" >
<property name= "configurationClass" value= "org.hibernate.cfg.AnnotationConfiguration" />
<property name= "dataSource" ref= "dataSource" />
<property name= "packagesToScan" value= "com.ltb.controladoria" />
<property name= "hibernateProperties" >
<props>
<prop key= "hibernate.show_sql" > true</prop>
<prop key= "format_sql" > true</prop>
<prop key= "hibernate.dialect" > org.hibernate.dialect.MySQLDialect</prop>
<prop key= "hibernate.id.new_generator_mappings" > true</prop>
<prop key= "hibernate.c3p0.acquire_increment" > 10</prop>
<prop key= "hibernate.c3p0.timeout" > 1800</prop>
<prop key= "hibernate.c3p0.idle_test_period" > 60</prop>
<prop key= "hibernate.c3p0.max_size" > 100</prop>
<prop key= "hibernate.c3p0.max_statements" > 50</prop>
<prop key= "hibernate.c3p0.min_size" > 5</prop>
<prop key= "hibernate.hbm2ddl.auto" > update</prop>
<prop key= "hibernate.envers.auditTablePrefix" > AUD_</prop>
<prop key= "hibernate.envers.storeDataAtDelete" > true</prop>
<prop key= "hibernate.ejb.event.post-insert" >
org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener
</prop>
<prop key= "hibernate.ejb.event.post-update" >
org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener
</prop>
</props>
</property>
//Incluido
<property name= "eventListeners" >
<map>
<entry key= "post-insert" >
<ref bean= "auditEventListener" />
</entry>
<entry key= "post-update" >
<ref bean= "auditEventListener" />
</entry>
<entry key= "post-delete" >
<ref bean= "auditEventListener" />
</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>
<tx:annotation-driven />
<bean id= "transactionManager" class= "org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "sessionFactory" ref= "sessionFactory" />
</bean>
</beans>
agora vou customizar para gravar tbm o id do usuario que fez as mudanças… obrigado.