private static Iterable<PersistEventListener> persistEventListeners(SessionImplementor session) { return session .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PERSIST ) .listeners(); }
private void firePersist(Map copiedAlready, PersistEvent event) { errorIfClosed(); checkTransactionSynchStatus(); for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) { listener.onPersist( event, copiedAlready ); } delayedAfterCompletion(); }
private void firePersist(PersistEvent event) { errorIfClosed(); checkTransactionSynchStatus(); checkNoUnresolvedActionsBeforeOperation(); for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) { listener.onPersist( event ); } checkNoUnresolvedActionsAfterOperation(); }
private void firePersistOnFlush(Map copiedAlready, PersistEvent event) { errorIfClosed(); checkTransactionSynchStatus(); for ( PersistEventListener listener : listeners( EventType.PERSIST_ONFLUSH ) ) { listener.onPersist( event, copiedAlready ); } delayedAfterCompletion(); }
private void firePersistOnFlush(PersistEvent event) { errorIfClosed(); checkTransactionSynchStatus(); checkNoUnresolvedActionsBeforeOperation(); for ( PersistEventListener listener : listeners( EventType.PERSIST_ONFLUSH ) ) { listener.onPersist( event ); } checkNoUnresolvedActionsAfterOperation(); }
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session) { final Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); final Type[] subTypes = virtualIdComponent.getSubtypes(); final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session ); final PersistenceContext persistenceContext = session.getPersistenceContext(); final int length = subTypes.length; for ( int i = 0 ; i < length; i++ ) { if ( propertyValues[i] == null ) { throw new HibernateException( "No part of a composite identifier may be null" ); } //JPA 2 @MapsId + @IdClass points to the pk of the entity if ( subTypes[i].isAssociationType() && ! copierSubTypes[i].isAssociationType() ) { // we need a session to handle this use case if ( session == null ) { throw new AssertionError( "Deprecated version of getIdentifier (no session) was used but session was required" ); } final Object subId; if ( HibernateProxy.class.isInstance( propertyValues[i] ) ) { subId = ( (HibernateProxy) propertyValues[i] ).getHibernateLazyInitializer().getIdentifier(); } else { EntityEntry pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] ); if ( pcEntry != null ) { subId = pcEntry.getId(); } else { LOG.debug( "Performing implicit derived identity cascade" ); final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session ); for ( PersistEventListener listener : persistEventListeners ) { listener.onPersist( event ); } pcEntry = persistenceContext.getEntry( propertyValues[i] ); if ( pcEntry == null || pcEntry.getId() == null ) { throw new HibernateException( "Unable to process implicit derived identity cascade" ); } else { subId = pcEntry.getId(); } } } propertyValues[i] = subId; } } mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }