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();
}
Aggregations