-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Envers conditional auditing, custom EnversIntegrator
PostPosted: Sun Feb 15, 2015 3:27 pm 
Newbie

Joined: Sun Feb 15, 2015 3:24 pm
Posts: 1
I need to configure conditional auditing using Hibernate Envers and Spring.

The default configuration works, but I want only the delete operations to be audited, saving the deleted entity in the audit table.

I've followed all the documentation steps but when I try the application with a simple main that creates and deletes an entity, my CustomEnversIntegrator is not called, instead the org.hibernate.envers.event.spi.EnversIntegrator is called.

Here is my spring-config.xml:
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaProperties">
        <props>
            <prop key="org.hibernate.envers.default_schema">macap_auditoria</prop>
            <prop key="org.hibernate.envers.audit_table_prefix">aud_</prop>
            <prop key="org.hibernate.envers.audit_table_suffix"></prop>
            <prop key="org.hibernate.envers.store_data_at_delete">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.listeners.envers.autoRegister">false</prop>
            <prop key="org.hibernate.envers.cascade_delete_revision">true</prop>
        </props>
    </property>
    ......


CustomEnversIntegrator.java, listening only to the delete operation:
Code:
    public class CustomEnversIntegrator extends EnversIntegrator {

private AuditConfiguration enversConfiguration;

@Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    final EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);
    enversConfiguration = AuditConfiguration.getFor(configuration, serviceRegistry.getService(ClassLoaderService.class));
    if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
        listenerRegistry.prependListeners(EventType.POST_DELETE, new CustomEnversPostDeleteEventListener(enversConfiguration));
    }
}
}


And lastly, I've added the file META-INF/services/org.hibernate.spi.Integrator with one line inside: uy.com.macap.ccd.services.persistence.audit.CustomEnversIntegrator

The jar generated in my .m2 folder contains the META-INF/services/org.hibernate.spi.Integrator file inside, so I don't know what else to try besides recompiling envers with the EnversIntegrator class modified by me.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.