Search in sources :

Example 1 with JpaFlushEventListener

use of org.hibernate.jpa.event.internal.core.JpaFlushEventListener in project hibernate-orm by hibernate.

the class LazyProxyOnEnhancedEntityTestTask method execute.

public void execute() {
    EventListenerRegistry registry = getFactory().unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(EventListenerRegistry.class);
    registry.prependListeners(EventType.FLUSH, new JpaFlushEventListener());
    registry.prependListeners(EventType.LOAD, new ImmediateLoadTrap());
    EntityManager em = getFactory().createEntityManager();
    em.getTransaction().begin();
    Parent p = em.find(Parent.class, parentID);
    // unwanted lazy load occurs here
    em.flush();
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) JpaFlushEventListener(org.hibernate.jpa.event.internal.core.JpaFlushEventListener) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

EntityManager (javax.persistence.EntityManager)1 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)1 JpaFlushEventListener (org.hibernate.jpa.event.internal.core.JpaFlushEventListener)1