Мне нужно настроить условный аудит с помощью Hibernate Envers и Spring.
Конфигурация по умолчанию работает, но я хочу, чтобы проверялись только операции удаления, сохраняя удаленный объект в таблице аудита.
Я выполнил все шаги документации но когда я пробую приложение с простым main, которое создает и удаляет объект, мой CustomEnversIntegrator не вызывается, вместо этого вызывается org.hibernate.envers.event.spi.EnversIntegrator.
Вот мой файл spring-config.xml:
<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:
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));
}
}
}
И, наконец, я добавил файл META-INF / services / org.hibernate.spi.Integrator с одной строчкой внутри: uy.com.macap.ccd.services.persistence.audit.CustomEnversIntegrator
Баночка, созданная в моей папке .m2, содержит файл META-INF / services / org.hibernate.spi.Integrator внутри, поэтому я не знаю, что еще попробовать, кроме перекомпиляции envers с измененным мной классом EnversIntegrator.
Спасибо.