'How to trigger Hibernate interceptor in the integration test?

I have created interceptor for boolean onFlushDirty method.

Registered it like that

@Component
public class HibernateInterceptorRegistration implements HibernatePropertiesCustomizer {

  // My interceptor
  private final EntityInterceptor entityInterceptor;

  public HibernateInterceptorRegistration(EntityInterceptor entityInterceptor) {
    this.entityInterceptor = entityInterceptor;
  }

  @Override
  public void customize(Map<String, Object> hibernateProperties) {
    hibernateProperties.put("hibernate.session_factory.interceptor", entityInterceptor);
  }
}

Application works correct, but I cannot trigger this interceptor in integrational test. I have TestConfig class, that I @Import to the integrational test class.

There I've added 2 beans:

  @Bean
  public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
    return new HibernateInterceptorRegistration(entityInterceptor());
  }

  @Bean
  public EntityInterceptor entityInterceptor() {
    return new EntityInterceptor();
  }

Nothing helped. What should I do to use interceptor in tests?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source