From 7ea75516b695ee0ffe2a6ce8b8225f2b545c7fab Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Thu, 10 Jan 2019 14:32:34 -0500 Subject: [PATCH] HHH-13164 - Revert changes made for HHH-11019. --- .../internal/AbstractSaveEventListener.java | 31 ++----------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java index 120f6c4e0d..39806b7d69 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java @@ -9,7 +9,6 @@ package org.hibernate.event.internal; import java.io.Serializable; import java.util.Map; -import org.hibernate.FlushMode; import org.hibernate.LockMode; import org.hibernate.NonUniqueObjectException; import org.hibernate.action.internal.AbstractEntityInsertAction; @@ -39,9 +38,6 @@ import org.hibernate.pretty.MessageHelper; import org.hibernate.type.Type; 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. * @@ -248,7 +244,8 @@ public abstract class AbstractSaveEventListener 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 // same object again. QUESTION: should this be done before onSave() is called? @@ -320,30 +317,6 @@ public abstract class AbstractSaveEventListener 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( Object[] values, Serializable id,