Created
May 6, 2015 20:10
-
-
Save gsmet/e8d3003344938b1d327b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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