From 815c4eb4a1db59ac0781cf04ead8ae018840cfa8 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 29 Nov 2022 16:00:53 -0600 Subject: [PATCH] HHH-15393 - Improve write-paths to use mapping model --- .../engine/internal/AbstractEntityEntry.java | 7 +- .../metamodel/internal/AttributeFactory.java | 93 +++++++------------ .../mapping/EntityIdentifierMapping.java | 29 ++++++ .../BasicEntityIdentifierMappingImpl.java | 5 + .../EmbeddedIdentifierMappingImpl.java | 7 +- ...InverseNonAggregatedIdentifierMapping.java | 5 + .../NonAggregatedIdentifierMappingImpl.java | 10 ++ ...mousTupleBasicEntityIdentifierMapping.java | 5 + ...sTupleEmbeddedEntityIdentifierMapping.java | 8 +- ...eNonAggregatedEntityIdentifierMapping.java | 14 ++- .../entity/AbstractEntityInitializer.java | 5 +- ...ractBatchEntitySelectFetchInitializer.java | 2 +- .../tuple/entity/EntityMetamodel.java | 2 +- .../BatchFetchStrategyHelperTest.java | 24 ++--- .../FetchStrategyHelperTest.java | 24 ++--- .../NoProxyFetchStrategyHelperTest.java | 23 +++-- 16 files changed, 151 insertions(+), 112 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java index 8ca515faa7..35075372d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java @@ -28,8 +28,8 @@ import org.hibernate.engine.spi.SelfDirtinessTracker; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.Status; +import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; @@ -311,7 +311,8 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { return null; } else { - final int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex( propertyName ); + final AttributeMapping attributeMapping = persister.findAttributeMapping( propertyName ); + final int propertyIndex = attributeMapping.getStateArrayPosition(); return loadedState[propertyIndex]; } } @@ -323,7 +324,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { assert propertyName != null; assert loadedState != null; - final int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex( propertyName ); + final int propertyIndex = persister.findAttributeMapping( propertyName ).getStateArrayPosition(); loadedState[propertyIndex] = collection; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 875274a945..219932ccab 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -10,7 +10,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; -import java.util.Iterator; import org.hibernate.AssertionFailure; import org.hibernate.PropertyNotFoundException; @@ -25,11 +24,14 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Value; import org.hibernate.metamodel.AttributeClassification; -import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.mapping.AttributeMapping; +import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; +import org.hibernate.metamodel.mapping.EntityIdentifierMapping; +import org.hibernate.metamodel.mapping.EntityVersionMapping; import org.hibernate.metamodel.model.domain.AbstractIdentifiableType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; @@ -49,10 +51,7 @@ import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.property.access.internal.PropertyAccessMapImpl; import org.hibernate.property.access.spi.Getter; -import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.type.AnyType; -import org.hibernate.type.BasicType; -import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EntityType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; @@ -306,36 +305,19 @@ public class AttributeFactory { private static EntityPersister getDeclaringEntity( AbstractIdentifiableType ownerType, MetadataContext metadataContext) { - final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); - if ( persistenceType == Type.PersistenceType.ENTITY ) { - return metadataContext.getMetamodel() - .getEntityDescriptor( ownerType.getTypeName() ); - } - else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) { - PersistentClass persistentClass = - metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl) ownerType ); - return metadataContext.getMetamodel() - .findEntityDescriptor( persistentClass.getClassName() ); - } - else { - throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType ); - } + return getDeclarerEntityPersister( ownerType, metadataContext ); } - private static EntityMetamodel getDeclarerEntityMetamodel( + + private static EntityPersister getDeclarerEntityPersister( AbstractIdentifiableType ownerType, MetadataContext metadataContext) { final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); if ( persistenceType == Type.PersistenceType.ENTITY ) { - return metadataContext.getMetamodel() - .getEntityDescriptor( ownerType.getTypeName() ) - .getEntityMetamodel(); + return metadataContext.getMetamodel().getEntityDescriptor( ownerType.getTypeName() ); } else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) { - PersistentClass persistentClass = - metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl) ownerType ); - return metadataContext.getMetamodel() - .findEntityDescriptor( persistentClass.getClassName() ) - .getEntityMetamodel(); + PersistentClass persistentClass = metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl) ownerType ); + return metadataContext.getMetamodel().findEntityDescriptor( persistentClass.getClassName() ); } else { throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType ); @@ -617,21 +599,16 @@ public class AttributeFactory { private static final MemberResolver virtualIdentifierMemberResolver = (attributeContext, metadataContext) -> { final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); - final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType, metadataContext ); - if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) { - throw new IllegalArgumentException( "expecting IdClass mapping" ); - } - - org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType(); - if ( !(type instanceof EmbeddedComponentType) ) { + final EntityPersister entityPersister = getDeclarerEntityPersister( identifiableType, metadataContext ); + final EntityIdentifierMapping identifierMapping = entityPersister.getIdentifierMapping(); + + if ( identifierMapping.getNature() != EntityIdentifierMapping.Nature.VIRTUAL ) { throw new IllegalArgumentException( "expecting IdClass mapping" ); } + final CompositeIdentifierMapping cid = (CompositeIdentifierMapping) identifierMapping; + final EmbeddableMappingType embeddable = cid.getPartMappingType(); final String attributeName = attributeContext.getPropertyMapping().getName(); - final EmbeddedComponentType componentType = (EmbeddedComponentType) type; - final EmbeddableValuedModelPart embeddedPart = ( (CompositeTypeImplementor) componentType ).getMappingModelPart(); - assert embeddedPart != null; - final EmbeddableMappingType embeddable = embeddedPart.getEmbeddableTypeDescriptor(); final AttributeMapping attributeMapping = embeddable.findAttributeMapping( attributeName ); if ( attributeMapping == null ) { throw new PropertyNotFoundException( @@ -658,16 +635,16 @@ public class AttributeFactory { else if ( Type.PersistenceType.ENTITY == persistenceType || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) { final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) ownerType; - final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); - final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); + final EntityPersister declaringEntityPersister = getDeclaringEntity( identifiableType, metadataContext ); final String propertyName = property.getName(); - final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName ); - if ( index == null ) { + + final AttributeMapping attributeMapping = declaringEntityPersister.findAttributeMapping( propertyName ); + if ( attributeMapping == null ) { // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext ); } else { - final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( property ).getGetter(); + final Getter getter = declaringEntityPersister.getRepresentationStrategy().resolvePropertyAccess( property ).getGetter(); return getter instanceof PropertyAccessMapImpl.GetterImpl ? new MapMember( propertyName, property.getType().getReturnedClass() ) : getter.getMember(); @@ -681,20 +658,16 @@ public class AttributeFactory { private final MemberResolver identifierMemberResolver = (attributeContext, metadataContext) -> { final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); - final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); - - if ( !attributeContext.getPropertyMapping().getName() - .equals( entityMetamodel.getIdentifierProperty().getName() ) ) { + final EntityIdentifierMapping identifierMapping = declaringEntityMapping.getIdentifierMapping(); + final String attributeName = attributeContext.getPropertyMapping().getName(); + if ( !attributeName.equals( identifierMapping.getAttributeName() ) ) { // this *should* indicate processing part of an IdClass... return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext ); } final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) { - return new MapMember( - entityMetamodel.getIdentifierProperty().getName(), - entityMetamodel.getIdentifierProperty().getType().getReturnedClass() - ); + return new MapMember( identifierMapping.getAttributeName(), identifierMapping.getJavaType().getJavaTypeClass() ); } else { return getter.getMember(); @@ -703,20 +676,20 @@ public class AttributeFactory { private final MemberResolver versionMemberResolver = (attributeContext, metadataContext) -> { final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); - final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); - final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); + final EntityPersister entityPersister = getDeclaringEntity( identifiableType, metadataContext ); + final EntityVersionMapping versionMapping = entityPersister.getVersionMapping(); + assert entityPersister.isVersioned(); + assert versionMapping != null; + final String versionPropertyName = attributeContext.getPropertyMapping().getName(); - if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) { + if ( !versionPropertyName.equals( versionMapping.getVersionAttribute().getAttributeName() ) ) { // this should never happen, but to be safe... throw new IllegalArgumentException( "Given property did not match declared version property" ); } - final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); + final Getter getter = entityPersister.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) { - return new MapMember( - versionPropertyName, - attributeContext.getPropertyMapping().getType().getReturnedClass() - ); + return new MapMember( versionPropertyName, versionMapping.getJavaType().getJavaTypeClass() ); } else { return getter.getMember(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java index fe4c36206a..31991e9d5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java @@ -19,6 +19,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; * @see jakarta.persistence.EmbeddedId */ public interface EntityIdentifierMapping extends ValueMapping, ModelPart { + String ROLE_LOCAL_NAME = "{id}"; @Override @@ -26,6 +27,16 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart { return ROLE_LOCAL_NAME; } + /** + * @see Nature + */ + Nature getNature(); + + /** + * The name of the attribute defining the id, if one + */ + String getAttributeName(); + /** * The strategy for distinguishing between detached and transient * state based on the identifier mapping @@ -89,4 +100,22 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart { void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session); Object instantiate(); + + enum Nature { + /** + * Single column id + */ + SIMPLE, + + /** + * @see jakarta.persistence.EmbeddedId + */ + COMPOSITE, + + /** + * Composite identifier defined with multiple {@link jakarta.persistence.Id} + * mappings. Often used in conjunction with an {@link jakarta.persistence.IdClass} + */ + VIRTUAL + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index d514d378d3..af42d01cf5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -132,6 +132,11 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa return attributeName; } + @Override + public Nature getNature() { + return Nature.SIMPLE; + } + @Override public IdentifierValue getUnsavedStrategy() { return unsavedStrategy; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java index 0c6057e230..b20d06d28e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java @@ -10,8 +10,8 @@ import java.util.function.BiConsumer; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.internal.AbstractCompositeIdentifierMapping; -import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.proxy.HibernateProxy; @@ -53,6 +53,11 @@ public class EmbeddedIdentifierMappingImpl return name; } + @Override + public Nature getNature() { + return Nature.COMPOSITE; + } + @Override public EmbeddableMappingType getPartMappingType() { return embeddableDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java index 403f5e15c4..8ab205fa87 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java @@ -92,6 +92,11 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp return super.getPartName(); } + @Override + public Nature getNature() { + return Nature.VIRTUAL; + } + @Override public EmbeddableMappingType getPartMappingType() { return (EmbeddableMappingType) super.getPartMappingType(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index 97c6a7940a..f5c91b9977 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -200,6 +200,16 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif return super.toSqlExpression( tableGroup, clause, walker, sqlAstCreationState ); } + @Override + public Nature getNature() { + return Nature.VIRTUAL; + } + + @Override + public String getAttributeName() { + return null; + } + @Override public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { return getIdentifier( entity ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicEntityIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicEntityIdentifierMapping.java index 5659d569b2..23894451e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicEntityIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicEntityIdentifierMapping.java @@ -33,6 +33,11 @@ public class AnonymousTupleBasicEntityIdentifierMapping this.delegate = delegate; } + @Override + public Nature getNature() { + return Nature.SIMPLE; + } + @Override public IdentifierValue getUnsavedStrategy() { return delegate.getUnsavedStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddedEntityIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddedEntityIdentifierMapping.java index 7ed01b9c47..f49a8b6477 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddedEntityIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddedEntityIdentifierMapping.java @@ -11,17 +11,14 @@ import java.util.Map; import org.hibernate.Incubating; import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; -import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.MappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.property.access.spi.PropertyAccess; -import org.hibernate.query.sqm.SqmExpressible; /** * @author Christian Beikov @@ -46,6 +43,11 @@ public class AnonymousTupleEmbeddedEntityIdentifierMapping extends AnonymousTupl this.delegate = delegate; } + @Override + public Nature getNature() { + return delegate.getNature(); + } + @Override public IdentifierValue getUnsavedStrategy() { return delegate.getUnsavedStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleNonAggregatedEntityIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleNonAggregatedEntityIdentifierMapping.java index e1b23ca1a7..3097d2f6d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleNonAggregatedEntityIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleNonAggregatedEntityIdentifierMapping.java @@ -13,17 +13,13 @@ import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.EmbeddableMappingType; -import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.MappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping; import org.hibernate.metamodel.mapping.internal.IdClassEmbeddable; -import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping; import org.hibernate.metamodel.mapping.internal.VirtualIdEmbeddable; import org.hibernate.metamodel.model.domain.DomainType; -import org.hibernate.property.access.spi.PropertyAccess; /** * @author Christian Beikov @@ -48,6 +44,16 @@ public class AnonymousTupleNonAggregatedEntityIdentifierMapping extends Anonymou this.delegate = delegate; } + @Override + public Nature getNature() { + return Nature.VIRTUAL; + } + + @Override + public String getAttributeName() { + return null; + } + @Override public IdentifierValue getUnsavedStrategy() { return delegate.getUnsavedStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java index d96e1f94c9..6a2c8ae654 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java @@ -41,7 +41,6 @@ import org.hibernate.metamodel.mapping.EntityVersionMapping; import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; @@ -62,9 +61,9 @@ import org.hibernate.type.AssociationType; import org.hibernate.type.BasicType; import org.hibernate.type.Type; +import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY; import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; -import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY; import static org.hibernate.internal.log.LoggingHelper.toLoggableString; /** @@ -734,7 +733,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces final AssociationType associationType = (AssociationType) propertyType; final String ukName = associationType.getLHSPropertyName(); if ( ukName != null ) { - final int index = ( (UniqueKeyLoadable) concreteDescriptor ).getPropertyIndex( ukName ); + final int index = concreteDescriptor.findAttributeMapping( ukName ).getStateArrayPosition(); final Type type = concreteDescriptor.getPropertyTypes()[index]; // polymorphism not really handled completely correctly, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java index b64db5840f..96cd317068 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java @@ -130,7 +130,7 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract } protected static int getPropertyIndex(EntityInitializer entityInitializer, String propertyName) { - return entityInitializer.getConcreteDescriptor().getPropertyIndex( propertyName ); + return entityInitializer.getConcreteDescriptor().findAttributeMapping( propertyName ).getStateArrayPosition(); } @Override 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 e9718ad299..573b80ca98 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 @@ -66,7 +66,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger; public class EntityMetamodel implements Serializable { private static final CoreMessageLogger LOG = messageLogger( EntityMetamodel.class ); - private static final int NO_VERSION_INDX = -66; + public static final int NO_VERSION_INDX = -66; private final SessionFactoryImplementor sessionFactory; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/BatchFetchStrategyHelperTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/BatchFetchStrategyHelperTest.java index 3dbfbd4424..be9a3a49cf 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/BatchFetchStrategyHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/BatchFetchStrategyHelperTest.java @@ -8,25 +8,25 @@ package org.hibernate.orm.test.fetchstrategyhelper; import java.util.HashSet; import java.util.Set; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; - -import org.junit.Test; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.persister.entity.OuterJoinLoadable; -import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.type.AssociationType; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import jakarta.persistence.ElementCollection; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import static org.junit.Assert.assertSame; /** @@ -175,7 +175,7 @@ public class BatchFetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return entityPersister.getFetchMode( index ); } @@ -183,7 +183,7 @@ public class BatchFetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return (AssociationType) entityPersister.getSubclassPropertyType( index ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/FetchStrategyHelperTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/FetchStrategyHelperTest.java index 22a290155a..d86f39a63d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/FetchStrategyHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/FetchStrategyHelperTest.java @@ -8,24 +8,24 @@ package org.hibernate.orm.test.fetchstrategyhelper; import java.util.HashSet; import java.util.Set; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; - -import org.junit.Test; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.persister.entity.OuterJoinLoadable; -import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.type.AssociationType; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import jakarta.persistence.ElementCollection; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import static org.junit.Assert.assertSame; /** @@ -171,7 +171,7 @@ public class FetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return entityPersister.getFetchMode( index ); } @@ -179,7 +179,7 @@ public class FetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return (AssociationType) entityPersister.getSubclassPropertyType( index ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/NoProxyFetchStrategyHelperTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/NoProxyFetchStrategyHelperTest.java index 5e6f40bdf0..6990cce8c5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/NoProxyFetchStrategyHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/fetchstrategyhelper/NoProxyFetchStrategyHelperTest.java @@ -6,24 +6,23 @@ */ package org.hibernate.orm.test.fetchstrategyhelper; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; - -import org.junit.Test; - import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.Proxy; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.persister.entity.OuterJoinLoadable; -import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.type.AssociationType; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import static org.junit.Assert.assertSame; /** @@ -93,7 +92,7 @@ public class NoProxyFetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return entityPersister.getFetchMode( index ); } @@ -101,7 +100,7 @@ public class NoProxyFetchStrategyHelperTest extends BaseCoreFunctionalTestCase { OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor(entityClass.getName()); - int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); + int index = entityPersister.getPropertyIndex( path ); return (AssociationType) entityPersister.getSubclassPropertyType( index ); }