We are using Hibernate with a Wildfly application server and are currently migrating from Wildfly 8.2.0 (Hibernate 4.3) to 10.1.0 (Hibernate 5.0).
With Hibernate 4.3 we could install a global Interceptor for all Sessions using a Hibernate Integrator.
Code:
public class MyIntegrator implements Integrator {
private static Logger logger = Logger.getLogger(MyIntegrator.class);
@Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
logger.info("Install GlobalInterceptor in " + configuration.getProperty("hibernate.session_factory_name"));
configuration.setInterceptor(new GlobalInterceptor());
}
...
}
This does not work anymore with Hibernate 5.0 since the API of Integrator has changed.
Instead of the Configuration Hibernate now passes a Metadata instance into integrate.
Code:
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
// TODO Set the Interceptor for all Sessions ... but how?
}
How can I set an Interceptor with the API of Metadata?
I couldn't find any information on this in the migration guides.
Or are there other ways the configure Hibernate to use an interceptor?
Thank you for any hints!
Christoph