Source:
<code>protected Serializable performSaveOrReplicate( Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) { Serializable id = key == null ? null : key.getIdentifier(); <START> boolean shouldDelayIdentityInserts = !isPartOfTransaction( source ) && !requiresImmediateIdAccess; <END> EntityEntry original = source.getPersistenceContext().addEntry( entity, Status.SAVING, null, null, id, null, LockMode.WRITE, useIdentityColumn, persister, false ); cascadeBeforeSave( source, persister, entity, anything ); Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source ); Type[] types = persister.getPropertyTypes(); boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source ); if ( persister.hasCollections() ) { substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source ); } if ( substitute ) { persister.setPropertyValues( entity, values ); } TypeHelper.deepCopy( values, types, persister.getPropertyUpdateability(), values, source ); AbstractEntityInsertAction insert = addInsertAction( values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts ); cascadeAfterSave( source, persister, entity, anything ); if ( useIdentityColumn && insert.isEarlyInsert() ) { if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) { throw new IllegalStateException( "Insert should be using an identity column, but action is of unexpected type: " + insert.getClass().getName() ); } id = ((EntityIdentityInsertAction) insert).getGeneratedId(); insert.handleNaturalIdPostSaveNotifications( id ); } EntityEntry newEntry = source.getPersistenceContext().getEntry( entity ); if ( newEntry != original ) { EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class ); if ( extraState == null ) { newEntry.addExtraState( original.getExtraState( EntityEntryExtraState.class ) ); } } return id; }</code><technical_language>I suppose this handled in a separate jira issue</technical_language>

Target:
protected Serializable performSaveOrReplicate( Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) { Serializable id = key == null ? null : key.getIdentifier(); boolean inTrx = source.isTransactionInProgress(); boolean shouldDelayIdentityInserts = !inTrx && !requiresImmediateIdAccess; EntityEntry original = source.getPersistenceContext().addEntry( entity, Status.SAVING, null, null, id, null, LockMode.WRITE, useIdentityColumn, persister, false ); cascadeBeforeSave( source, persister, entity, anything ); Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source ); Type[] types = persister.getPropertyTypes(); boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source ); if ( persister.hasCollections() ) { substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source ); } if ( substitute ) { persister.setPropertyValues( entity, values ); } TypeHelper.deepCopy( values, types, persister.getPropertyUpdateability(), values, source ); AbstractEntityInsertAction insert = addInsertAction( values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts ); cascadeAfterSave( source, persister, entity, anything ); if ( useIdentityColumn && insert.isEarlyInsert() ) { if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) { throw new IllegalStateException( "Insert should be using an identity column, but action is of unexpected type: " + insert.getClass().getName() ); } id = ((EntityIdentityInsertAction) insert).getGeneratedId(); insert.handleNaturalIdPostSaveNotifications( id ); } EntityEntry newEntry = source.getPersistenceContext().getEntry( entity ); if ( newEntry != original ) { EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class ); if ( extraState == null ) { newEntry.addExtraState( original.getExtraState( EntityEntryExtraState.class ) ); } } return id; }