HHH-13164 - Revert changes made for HHH-11019.

This commit is contained in:
Chris Cranford 2019-01-10 14:32:34 -05:00 committed by Gail Badner
parent 6002a7bd7a
commit 7ea75516b6
1 changed files with 2 additions and 29 deletions

View File

@ -9,7 +9,6 @@ package org.hibernate.event.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.hibernate.FlushMode;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException; import org.hibernate.NonUniqueObjectException;
import org.hibernate.action.internal.AbstractEntityInsertAction; import org.hibernate.action.internal.AbstractEntityInsertAction;
@ -39,9 +38,6 @@ import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper; import org.hibernate.type.TypeHelper;
import static org.hibernate.FlushMode.COMMIT;
import static org.hibernate.FlushMode.MANUAL;
/** /**
* A convenience base class for listeners responding to save events. * A convenience base class for listeners responding to save events.
* *
@ -248,7 +244,8 @@ public abstract class AbstractSaveEventListener
Serializable id = key == null ? null : key.getIdentifier(); Serializable id = key == null ? null : key.getIdentifier();
boolean shouldDelayIdentityInserts = shouldDelayIdentityInserts( requiresImmediateIdAccess, source ); boolean inTrx = source.isTransactionInProgress();
boolean shouldDelayIdentityInserts = !inTrx && !requiresImmediateIdAccess;
// Put a placeholder in entries, so we don't recurse back and try to save() the // Put a placeholder in entries, so we don't recurse back and try to save() the
// same object again. QUESTION: should this be done before onSave() is called? // same object again. QUESTION: should this be done before onSave() is called?
@ -320,30 +317,6 @@ public abstract class AbstractSaveEventListener
return id; return id;
} }
private static boolean shouldDelayIdentityInserts(boolean requiresImmediateIdAccess, EventSource source) {
return shouldDelayIdentityInserts( requiresImmediateIdAccess, isPartOfTransaction( source ), source.getHibernateFlushMode() );
}
private static boolean shouldDelayIdentityInserts(
boolean requiresImmediateIdAccess,
boolean partOfTransaction,
FlushMode flushMode) {
if ( requiresImmediateIdAccess ) {
// todo : make this configurable? as a way to support this behavior with Session#save etc
return false;
}
// otherwise we should delay the IDENTITY insertions if either:
// 1) we are not part of a transaction
// 2) we are in FlushMode MANUAL or COMMIT (not AUTO nor ALWAYS)
return !partOfTransaction || flushMode == MANUAL || flushMode == COMMIT;
}
private static boolean isPartOfTransaction(EventSource source) {
return source.isTransactionInProgress() && source.getTransactionCoordinator().isJoined();
}
private AbstractEntityInsertAction addInsertAction( private AbstractEntityInsertAction addInsertAction(
Object[] values, Object[] values,
Serializable id, Serializable id,