From b26ec4e6255a9e17dda7dfbc299d1f37ad51d136 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 3 Sep 2019 14:43:37 -0700 Subject: [PATCH] HHH-13611 : Restore EntityMetamodel constructor to take SessionFactoryImplementor argument instead of PersisterCreationContext --- .../spi/interceptor/EnhancementHelper.java | 5 +-- .../interceptor/LazyAttributesMetadata.java | 7 ++-- .../entity/AbstractEntityPersister.java | 20 ++---------- .../org/hibernate/tuple/PropertyFactory.java | 7 ++-- .../BytecodeEnhancementMetadataPojoImpl.java | 6 ++-- .../tuple/entity/EntityMetamodel.java | 32 +++---------------- .../test/legacy/CustomPersister.java | 2 +- 7 files changed, 16 insertions(+), 63 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java index 91d865ac49..7c509cfe32 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java @@ -8,7 +8,6 @@ package org.hibernate.bytecode.enhance.spi.interceptor; import java.util.Locale; import java.util.function.BiFunction; -import java.util.function.Function; import org.hibernate.FlushMode; import org.hibernate.LazyInitializationException; @@ -31,8 +30,7 @@ public class EnhancementHelper { public static boolean includeInBaseFetchGroup( Property bootMapping, boolean isEnhanced, - boolean allowEnhancementAsProxy, - Function hasSubclassChecker) { + boolean allowEnhancementAsProxy) { final Value value = bootMapping.getValue(); if ( ! isEnhanced ) { @@ -57,7 +55,6 @@ public class EnhancementHelper { } // include it in the base fetch group so long as the config allows // using the FK to create an "enhancement proxy" -// return allowEnhancementAsProxy && hasSubclassChecker.apply( toOne.getReferencedEntityName() ); return allowEnhancementAsProxy; } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java index 380b17711c..8192d3d132 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java @@ -16,7 +16,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -34,8 +33,7 @@ public class LazyAttributesMetadata implements Serializable { public static LazyAttributesMetadata from( PersistentClass mappedEntity, boolean isEnhanced, - boolean allowEnhancementAsProxy, - Function hasSubclassChecker) { + boolean allowEnhancementAsProxy) { final Map lazyAttributeDescriptorMap = new LinkedHashMap<>(); final Map> fetchGroupToAttributesMap = new HashMap<>(); @@ -48,8 +46,7 @@ public class LazyAttributesMetadata implements Serializable { final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( property, isEnhanced, - allowEnhancementAsProxy, - hasSubclassChecker + allowEnhancementAsProxy ); if ( lazy ) { final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index d2b78ee95f..1a3265db1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -568,7 +568,7 @@ public abstract class AbstractEntityPersister this.naturalIdRegionAccessStrategy = null; } - this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext ); + this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext.getSessionFactory() ); this.entityTuplizer = this.entityMetamodel.getTuplizer(); if ( entityMetamodel.isMutable() ) { @@ -704,14 +704,7 @@ public abstract class AbstractEntityPersister final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( prop, entityMetamodel.isInstrumented(), - creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(), - associatedEntityName -> { - final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName ); - if ( bootEntityDescriptor == null ) { - return false; - } - return bootEntityDescriptor.hasSubclasses(); - } + creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled() ); if ( lazy ) { @@ -787,14 +780,7 @@ public abstract class AbstractEntityPersister final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( prop, entityMetamodel.isInstrumented(), - creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(), - associatedEntityName -> { - final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName ); - if ( bootEntityDescriptor == null ) { - return false; - } - return bootEntityDescriptor.hasSubclasses(); - } + creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled() ); while ( colIter.hasNext() ) { Selectable thing = (Selectable) colIter.next(); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java index a8004fa92f..779c114e70 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java @@ -7,7 +7,6 @@ package org.hibernate.tuple; import java.lang.reflect.Constructor; -import java.util.function.Function; import org.hibernate.EntityMode; import org.hibernate.HibernateException; @@ -155,8 +154,7 @@ public final class PropertyFactory { SessionFactoryImplementor sessionFactory, int attributeNumber, Property property, - boolean lazyAvailable, - Function hasSubclassChecker) { + boolean lazyAvailable) { final Type type = property.getValue().getType(); final NonIdentifierAttributeNature nature = decode( type ); @@ -174,8 +172,7 @@ public final class PropertyFactory { final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( property, lazyAvailable, - sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), - hasSubclassChecker + sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled() ); switch ( nature ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java index 390db7b179..cad2b64c9f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java @@ -8,7 +8,6 @@ package org.hibernate.tuple.entity; import java.io.Serializable; import java.util.Set; -import java.util.function.Function; import org.hibernate.LockMode; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; @@ -38,12 +37,11 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc PersistentClass persistentClass, Set identifierAttributeNames, CompositeType nonAggregatedCidMapper, - boolean allowEnhancementAsProxy, - Function hasSubclassChecker) { + boolean allowEnhancementAsProxy) { final Class mappedClass = persistentClass.getMappedClass(); final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom( mappedClass ); final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading - ? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy, hasSubclassChecker ) + ? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy ) : LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() ); return new BytecodeEnhancementMetadataPojoImpl( diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 0e4de4531e..298cd24482 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -33,7 +33,6 @@ import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.IdentifierProperty; import org.hibernate.tuple.InDatabaseValueGenerationStrategy; @@ -128,8 +127,8 @@ public class EntityMetamodel implements Serializable { public EntityMetamodel( PersistentClass persistentClass, EntityPersister persister, - final PersisterCreationContext creationContext) { - this.sessionFactory = creationContext.getSessionFactory(); + SessionFactoryImplementor sessionFactory) { + this.sessionFactory = sessionFactory; name = persistentClass.getEntityName(); rootName = persistentClass.getRootClass().getEntityName(); @@ -164,14 +163,7 @@ public class EntityMetamodel implements Serializable { persistentClass, idAttributeNames, nonAggregatedCidMapper, - sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), - associatedEntityName -> { - final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName ); - if ( bootEntityDescriptor == null ) { - return false; - } - return bootEntityDescriptor.hasSubclasses(); - } + sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled() ); } else { @@ -234,14 +226,7 @@ public class EntityMetamodel implements Serializable { sessionFactory, i, prop, - bytecodeEnhancementMetadata.isEnhancedForLazyLoading(), - associatedEntityName -> { - final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName ); - if ( bootEntityDescriptor == null ) { - return false; - } - return bootEntityDescriptor.hasSubclasses(); - } + bytecodeEnhancementMetadata.isEnhancedForLazyLoading() ); } @@ -260,14 +245,7 @@ public class EntityMetamodel implements Serializable { boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( prop, bytecodeEnhancementMetadata.isEnhancedForLazyLoading(), - sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), - associatedEntityName -> { - final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName ); - if ( bootEntityDescriptor == null ) { - return false; - } - return bootEntityDescriptor.hasSubclasses(); - } + sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled() ); if ( lazy ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/CustomPersister.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/CustomPersister.java index d79fa014e8..833cf33961 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/CustomPersister.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/CustomPersister.java @@ -71,7 +71,7 @@ public class CustomPersister implements EntityPersister { NaturalIdDataAccess naturalIdRegionAccessStrategy, PersisterCreationContext creationContext) { this.factory = creationContext.getSessionFactory(); - this.entityMetamodel = new EntityMetamodel( model, this, creationContext ); + this.entityMetamodel = new EntityMetamodel( model, this, creationContext.getSessionFactory() ); } public boolean hasLazyProperties() {