javaspringspring-boothibernateinterceptor

Hibernate 6 interceptor with Spring Boot 3


I am upgrading application from Spring Boot 2.7 and Hibernate 5.6 to Spring Boot 3.0 and Hibernate 6.2.

The application has interceptor implementing org.hibernate.Interceptor that is registered using application.yml and property spring.jpa.properties.hibernate.ejb.interceptor like this:

spring:
  jpa:
    properties:
      hibernate:
        ejb:
          interceptor: org.company.MyInterceptor

The problem is simple, after performing the upgrade the interceptor stopped working. I haven't read any changes in this regard in Hibernate or Spring Boot changelogs or migration guides, so I am wondering why this isn't working anymore.

I've also read official Hibernate docs and article on Baeldung on interceptors that suggest doing something like this:

SessionFactory sessionFactory = getSessionFactoryBuilder(serviceRegistry)
  .applyInterceptor(new CustomInterceptor())
  .build();

but since everything is Spring managed and we don't use any code like this directly I am lost at how this should be applied to Spring application


Solution

  • Just to mark this question as answered, the solution, as said by Andy Wilkinson in the comments, is to use this property instead:

    hibernate.session_factory.interceptor