use of org.hibernate.cfg.beanvalidation.BeanValidationEventListener in project candlepin by candlepin.
the class CandlepinContextListener method insertValidationEventListeners.
/**
* There's no way to really get Guice to perform injections on stuff that
* the JpaPersistModule is creating, so we resort to grabbing the EntityManagerFactory
* after the fact and adding the Validation EventListener ourselves.
* @param injector
*/
private void insertValidationEventListeners(Injector injector) {
javax.inject.Provider<EntityManagerFactory> emfProvider = injector.getProvider(EntityManagerFactory.class);
HibernateEntityManagerFactory hibernateEntityManagerFactory = (HibernateEntityManagerFactory) emfProvider.get();
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
EventListenerRegistry registry = sessionFactoryImpl.getServiceRegistry().getService(EventListenerRegistry.class);
javax.inject.Provider<BeanValidationEventListener> listenerProvider = injector.getProvider(BeanValidationEventListener.class);
registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listenerProvider.get());
}
use of org.hibernate.cfg.beanvalidation.BeanValidationEventListener in project candlepin by candlepin.
the class DatabaseTestFixture method insertValidationEventListeners.
/**
* There's no way to really get Guice to perform injections on stuff that
* the JpaPersistModule is creating, so we resort to grabbing the EntityManagerFactory
* after the fact and adding the Validation EventListener ourselves.
* @param inj
*/
private static void insertValidationEventListeners(Injector inj) {
Provider<EntityManagerFactory> emfProvider = inj.getProvider(EntityManagerFactory.class);
HibernateEntityManagerFactory hibernateEntityManagerFactory = (HibernateEntityManagerFactory) emfProvider.get();
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
EventListenerRegistry registry = sessionFactoryImpl.getServiceRegistry().getService(EventListenerRegistry.class);
Provider<BeanValidationEventListener> listenerProvider = inj.getProvider(BeanValidationEventListener.class);
registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listenerProvider.get());
}
Aggregations