HHH-13164 - Revert changes made for HHH-13147 HHH-13053 HHH-13044 HHH-13042 and HHH-11019.

This commit is contained in:
Chris Cranford 2018-12-18 08:47:07 -05:00
parent a57a2a5620
commit 16a9b5b225
6 changed files with 10 additions and 139 deletions

View File

@ -83,7 +83,6 @@ import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATE
import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE;
import static org.hibernate.cfg.AvailableSettings.DELAY_ENTITY_LOADER_CREATIONS;
import static org.hibernate.cfg.AvailableSettings.DISABLE_DELAYED_IDENTIFIER_POST_INSERTS;
import static org.hibernate.cfg.AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS;
import static org.hibernate.cfg.AvailableSettings.FAIL_ON_PAGINATION_OVER_COLLECTION_FETCH;
import static org.hibernate.cfg.AvailableSettings.FLUSH_BEFORE_COMPLETION;
@ -346,9 +345,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
this.defaultNullPrecedence = NullPrecedence.parse( defaultNullPrecedence );
this.orderUpdatesEnabled = ConfigurationHelper.getBoolean( ORDER_UPDATES, configurationSettings );
this.orderInsertsEnabled = ConfigurationHelper.getBoolean( ORDER_INSERTS, configurationSettings );
this.postInsertIdentifierDelayed = !ConfigurationHelper.getBoolean(
DISABLE_DELAYED_IDENTIFIER_POST_INSERTS, configurationSettings, false
);
this.callbacksEnabled = ConfigurationHelper.getBoolean( JPA_CALLBACKS_ENABLED, configurationSettings, true );
@ -1054,11 +1050,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return queryStatisticsMaxSize;
}
@Override
public boolean isPostInsertIdentifierDelayableEnabled() {
return postInsertIdentifierDelayed;
}
@Override
public boolean areJPACallbacksEnabled() {
return callbacksEnabled;

View File

@ -296,6 +296,10 @@ public interface SessionFactoryOptions {
return Statistics.DEFAULT_QUERY_STATISTICS_MAX_SIZE;
}
/**
* @deprecated Since 5.4.1, this is no longer used.
*/
@Deprecated
default boolean isPostInsertIdentifierDelayableEnabled() {
return true;
}

View File

@ -2003,19 +2003,4 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
* @since 5.4
*/
String SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY = "hibernate.id.sequence.increment_size_mismatch_strategy";
/**
* This setting controls whether the default behavior for delayed identity inserts is disabled.
* </p>
* Hibernate defines a set of rules that are used to determine if an insert statement that has
* an identity-based column can be delayed until flush/commit or if the statement must be
* executed early because access to the identity column is needed.
* </p>
* In the event that those defined rules are insufficient for a given mapping scenario, this
* setting can be set to {@code true} to permanently disable delayed identity inserts for all
* transactions as a short-term workaround.
* </p>
* The default value is {@code false}.
*/
String DISABLE_DELAYED_IDENTIFIER_POST_INSERTS = "hibernate.id.disable_delayed_identifier_post_inserts";
}

View File

@ -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, persister );
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,46 +317,6 @@ public abstract class AbstractSaveEventListener
return id;
}
private static boolean shouldDelayIdentityInserts(boolean requiresImmediateIdAccess, EventSource source, EntityPersister persister) {
return shouldDelayIdentityInserts( requiresImmediateIdAccess, isPartOfTransaction( source ), source.getHibernateFlushMode(), persister );
}
private static boolean shouldDelayIdentityInserts(
boolean requiresImmediateIdAccess,
boolean partOfTransaction,
FlushMode flushMode,
EntityPersister persister) {
if ( !persister.getFactory().getSessionFactoryOptions().isPostInsertIdentifierDelayableEnabled() ) {
return false;
}
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)
if ( !partOfTransaction || flushMode == MANUAL || flushMode == COMMIT ) {
if ( persister.canIdentityInsertBeDelayed() ) {
return true;
}
LOG.debugf(
"Identity insert for entity [%s] should be delayed; however the persister requested early insert.",
persister.getEntityName()
);
return false;
}
else {
return false;
}
}
private static boolean isPartOfTransaction(EventSource source) {
return source.isTransactionInProgress() && source.getTransactionCoordinator().isJoined();
}
private AbstractEntityInsertAction addInsertAction(
Object[] values,
Serializable id,

View File

@ -77,11 +77,9 @@ import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.ForeignGenerator;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.PostInsertIdentifierGenerator;
import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.insert.Binder;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.internal.CoreLogging;
@ -109,7 +107,6 @@ import org.hibernate.mapping.Table;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.persister.walking.internal.EntityIdentifierDefinitionHelper;
import org.hibernate.persister.walking.spi.AttributeDefinition;
@ -298,8 +295,6 @@ public abstract class AbstractEntityPersister
private final boolean useReferenceCacheEntries;
private boolean canIdentityInsertBeDelayed;
protected void addDiscriminatorToInsert(Insert insert) {
}
@ -962,11 +957,6 @@ public abstract class AbstractEntityPersister
return useReferenceCacheEntries;
}
@Override
public boolean canIdentityInsertBeDelayed() {
return canIdentityInsertBeDelayed;
}
protected static String getTemplateFromString(String string, SessionFactoryImplementor factory) {
return string == null ?
null :
@ -4158,64 +4148,6 @@ public abstract class AbstractEntityPersister
return new SubstituteBracketSQLQueryParser( sql, getFactory() ).process();
}
private void resolveIdentityInsertDelayable() {
// By default they can
// The remainder of this method checks use cases where we shouldn't permit it.
canIdentityInsertBeDelayed = true;
if ( getEntityMetamodel().getIdentifierProperty().isIdentifierAssignedByInsert() ) {
// if the persister writes the entity to the second-level cache; we cannot delay.
if ( canWriteToCache ) {
canIdentityInsertBeDelayed = false;
return;
}
// if the persister's identifier is assigned by insert, we need to see if we must force non-delay mode.
for ( NonIdentifierAttribute attribute : getEntityMetamodel().getProperties() ) {
if ( isTypeSelfReferencing( attribute.getType() ) ) {
canIdentityInsertBeDelayed = false;
}
}
}
}
private boolean isTypeSelfReferencing(Type propertyType) {
if ( propertyType.isAssociationType() ) {
if ( propertyType.isEntityType() ) {
Class<?> entityClass = propertyType.getReturnedClass();
if ( getMappedClass().equals( propertyType.getReturnedClass() ) ) {
return true;
}
}
else if ( propertyType.isCollectionType() ) {
// Association is a collection where owner needs identifier up-front
final CollectionType collection = (CollectionType) propertyType;
final CollectionPersister collectionPersister = getFactory().getMetamodel().collectionPersister( collection.getRole() );
if ( collectionPersister.isInverse() ) {
final EntityPersister entityPersister = collectionPersister.getOwnerEntityPersister();
if ( collectionPersister.getOwnerEntityPersister().equals( this ) ) {
final QueryableCollection queryableCollection = (QueryableCollection) collectionPersister;
final IdentifierGenerator identifierGenerator = queryableCollection.getElementPersister().getIdentifierGenerator();
// todo - perhaps this can be simplified
if ( ( identifierGenerator instanceof ForeignGenerator ) || ( identifierGenerator instanceof SequenceStyleGenerator ) ) {
return true;
}
}
}
}
}
else if ( propertyType.isComponentType() ) {
final CompositeType componentType = (CompositeType) propertyType;
for ( Type componentSubType : componentType.getSubtypes() ) {
if ( isTypeSelfReferencing( componentSubType ) ) {
return true;
}
}
}
return false;
}
public final void postInstantiate() throws MappingException {
doLateInit();
@ -4223,8 +4155,6 @@ public abstract class AbstractEntityPersister
createUniqueKeyLoaders();
createQueryLoader();
resolveIdentityInsertDelayable();
doPostInstantiate();
}

View File

@ -812,6 +812,10 @@ public interface EntityPersister extends EntityDefinition {
boolean canUseReferenceCacheEntries();
/**
* @deprecated Since 5.4.1, this is no longer used.
*/
@Deprecated
default boolean canIdentityInsertBeDelayed() {
return false;
}