Spring Boot 1.5.6
I was having the same problem using a more recent Hibernate with an on cascade delete
: envers wanted to insert a record that referenced the deleted ID, throwing a constraint violation.
Just adding this answer, in case someone finds it useful.
Turn off all envers listeners in application.properties
(and your equivalent test configuration if you have one).
spring.jpa.properties.hibernate.envers.autoRegisterListeners=false
Add the ones you want (here I only want insert and update).
@Component
public class HibernateListenerConfigurer
{
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;
@PostConstruct
protected void init()
{
SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
EnversService enversService = sessionFactory.getServiceRegistry().getService(EnversService.class);
registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(new EnversPostInsertEventListenerImpl(enversService));
registry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(new EnversPostUpdateEventListenerImpl(enversService));
}
}