Search in sources :

Example 6 with PostInsertEvent

use of org.hibernate.event.spi.PostInsertEvent in project hibernate-orm by hibernate.

the class EntityIdentityInsertAction method postCommitInsert.

private void postCommitInsert(boolean success) {
    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup(EventType.POST_COMMIT_INSERT);
    if (listenerGroup.isEmpty()) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(getInstance(), generatedId, getState(), getPersister(), eventSource());
    for (PostInsertEventListener listener : listenerGroup.listeners()) {
        if (PostCommitInsertEventListener.class.isInstance(listener)) {
            if (success) {
                listener.onPostInsert(event);
            } else {
                ((PostCommitInsertEventListener) listener).onPostInsertCommitFailed(event);
            }
        } else {
            //default to the legacy implementation that always fires the event
            listener.onPostInsert(event);
        }
    }
}
Also used : PostInsertEventListener(org.hibernate.event.spi.PostInsertEventListener) PostCommitInsertEventListener(org.hibernate.event.spi.PostCommitInsertEventListener) PostInsertEvent(org.hibernate.event.spi.PostInsertEvent)

Example 7 with PostInsertEvent

use of org.hibernate.event.spi.PostInsertEvent in project hibernate-orm by hibernate.

the class EntityInsertAction method postCommitInsert.

private void postCommitInsert(boolean success) {
    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup(EventType.POST_COMMIT_INSERT);
    if (listenerGroup.isEmpty()) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(getInstance(), getId(), getState(), getPersister(), eventSource());
    for (PostInsertEventListener listener : listenerGroup.listeners()) {
        if (PostCommitInsertEventListener.class.isInstance(listener)) {
            if (success) {
                listener.onPostInsert(event);
            } else {
                ((PostCommitInsertEventListener) listener).onPostInsertCommitFailed(event);
            }
        } else {
            //default to the legacy implementation that always fires the event
            listener.onPostInsert(event);
        }
    }
}
Also used : PostInsertEventListener(org.hibernate.event.spi.PostInsertEventListener) PostCommitInsertEventListener(org.hibernate.event.spi.PostCommitInsertEventListener) PostInsertEvent(org.hibernate.event.spi.PostInsertEvent)

Aggregations

PostInsertEvent (org.hibernate.event.spi.PostInsertEvent)7 PostInsertEventListener (org.hibernate.event.spi.PostInsertEventListener)7 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)3 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 PostCommitInsertEventListener (org.hibernate.event.spi.PostCommitInsertEventListener)2 PreInsertEvent (org.hibernate.event.spi.PreInsertEvent)2 PreInsertEventListener (org.hibernate.event.spi.PreInsertEventListener)2 IrrelevantEntity (org.hibernate.IrrelevantEntity)1 Session (org.hibernate.Session)1 TestForIssue (org.hibernate.testing.TestForIssue)1 Test (org.junit.Test)1