Skip to content

Instantly share code, notes, and snippets.

@gsmet
Created May 6, 2015 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsmet/e8d3003344938b1d327b to your computer and use it in GitHub Desktop.
Save gsmet/e8d3003344938b1d327b to your computer and use it in GitHub Desktop.
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