use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class LazyProxyOnEnhancedEntityTest method test.
@Test
public void test() {
EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
registry.prependListeners(EventType.LOAD, new ImmediateLoadTrap());
doInJPA(this::sessionFactory, em -> {
em.find(Parent.class, parentID);
// unwanted lazy load occurs on flush
});
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class RegisterUserEventListenersTest method testTransactionProcessSynchronization.
@Test
@TestForIssue(jiraKey = "HHH-7478")
public void testTransactionProcessSynchronization() {
final EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
final CountingPostInsertTransactionBoundaryListener listener = new CountingPostInsertTransactionBoundaryListener();
registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(listener);
Session session = openSession();
session.getTransaction().begin();
StrTestEntity entity = new StrTestEntity("str1");
session.save(entity);
session.getTransaction().commit();
session.close();
// Post insert listener invoked three times - before/after insertion of original data,
// revision entity and audit row.
Assert.assertEquals(3, listener.getBeforeCount());
Assert.assertEquals(3, listener.getAfterCount());
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class PreInsertEventListenerVetoBidirectionalTest method afterSessionFactoryBuilt.
@Override
protected void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt();
EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
registry.appendListeners(EventType.PRE_INSERT, (PreInsertEventListener) event -> event.getEntity() instanceof Parent);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project hibernate-orm by hibernate.
the class PreInsertEventListenerVetoUnidirectionalTest method afterSessionFactoryBuilt.
@Override
protected void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt();
EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
registry.appendListeners(EventType.PRE_INSERT, (PreInsertEventListener) event -> event.getEntity() instanceof Parent);
}
use of org.hibernate.event.service.spi.EventListenerRegistry in project webpieces by deanhiller.
the class HibernateEntityMeterBinder method bindTo.
@Override
public void bindTo(@NonNull MeterRegistry meterRegistry) {
if (sessionFactory instanceof SessionFactoryImplementor) {
EventListenerRegistry eventListenerRegistry = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
EntityEventListener eventListener = new EntityEventListener(meterRegistry);
eventListenerRegistry.appendListeners(EventType.POST_LOAD, eventListener);
eventListenerRegistry.appendListeners(EventType.POST_DELETE, eventListener);
eventListenerRegistry.appendListeners(EventType.POST_UPDATE, eventListener);
eventListenerRegistry.appendListeners(EventType.POST_INSERT, eventListener);
}
}
Aggregations