Search in sources :

Example 1 with BeanValidationEventListener

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());
}
Also used : BeanValidationEventListener(org.hibernate.cfg.beanvalidation.BeanValidationEventListener) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 2 with BeanValidationEventListener

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());
}
Also used : BeanValidationEventListener(org.hibernate.cfg.beanvalidation.BeanValidationEventListener) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateEntityManagerFactory(org.hibernate.ejb.HibernateEntityManagerFactory) HibernateEntityManagerFactory(org.hibernate.ejb.HibernateEntityManagerFactory) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)2 BeanValidationEventListener (org.hibernate.cfg.beanvalidation.BeanValidationEventListener)2 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)2 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)2 HibernateEntityManagerFactory (org.hibernate.ejb.HibernateEntityManagerFactory)1 HibernateEntityManagerFactory (org.hibernate.jpa.HibernateEntityManagerFactory)1