Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class InterceptorAwareHibernatePersistenceProvider extends HibernatePersistenceProvider {
private static final Logger LOGGER = Logger.getLogger(InterceptorAwareHibernatePersistenceProvider.class);
@Autowired
private Interceptor interceptor;
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader providedClassLoader) {
return new EntityManagerFactoryBuilderImpl(persistenceUnitDescriptor, integration, providedClassLoader) {
@Override
public Settings configure(StandardServiceRegistryBuilder ssrBuilder) {
Settings configuration = super.buildHibernateConfiguration(serviceRegistry);
if (InterceptorAwareHibernatePersistenceProvider.this.interceptor != null) {
if (configuration.getInterceptor() != null
&& !EmptyInterceptor.class.equals(configuration.getInterceptor().getClass())) {
LOGGER.error("The persistence provider was already configured with an interceptor: we override it.");
}
configuration.setInterceptor(InterceptorAwareHibernatePersistenceProvider.this.interceptor);
}
return configuration;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.