From d63ff31b59a7e656737020bf595b830bbf7b0720 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Wed, 22 Mar 2023 16:09:46 +0100 Subject: [PATCH] HHH-16353 Make it possible for Hibernate Reactive to override the creation of AttributeMapping and Fetch strategies --- .../internal/AbstractAttributeMapping.java | 5 + .../AbstractEntityCollectionPart.java | 46 +++++++- .../AbstractSingularAttributeMapping.java | 6 + .../AbstractStateArrayContributorMapping.java | 10 ++ .../internal/MappingModelCreationHelper.java | 103 +++++++++++++---- .../internal/OneToManyCollectionPart.java | 6 + .../internal/PluralAttributeMappingImpl.java | 79 ++++++++++++- .../internal/ToOneAttributeMapping.java | 107 ++++++++++++------ .../entity/AbstractEntityPersister.java | 90 ++++++++++++++- .../internal/EntityFetchJoinedImpl.java | 40 ++++++- 10 files changed, 429 insertions(+), 63 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java index 0c2ce944da..e65835752d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java @@ -27,6 +27,11 @@ public AbstractAttributeMapping(String name, int fetchableIndex, ManagedMappingT this.declaringType = declaringType; } + // For Hibernate Reactive + protected AbstractAttributeMapping(AbstractAttributeMapping original) { + this( original.name, original.fetchableIndex, original.declaringType ); + } + @Override public ManagedMappingType getDeclaringType() { return declaringType; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityCollectionPart.java index 624f411e24..ad6b3e1455 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityCollectionPart.java @@ -23,6 +23,7 @@ import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.PropertyMapping; @@ -41,6 +42,7 @@ import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchParent; +import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch; import org.hibernate.sql.results.graph.entity.EntityFetch; import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl; import org.hibernate.type.CompositeType; @@ -82,6 +84,16 @@ public AbstractEntityCollectionPart( ); } + // For Hibernate Reactive + protected AbstractEntityCollectionPart(AbstractEntityCollectionPart original) { + this.navigableRole = original.navigableRole; + this.nature = original.nature; + this.collectionDescriptor = original.collectionDescriptor; + this.associatedEntityTypeDescriptor = original.associatedEntityTypeDescriptor; + this.notFoundAction = original.notFoundAction; + this.targetKeyPropertyNames = original.targetKeyPropertyNames; + } + @Override public String toString() { return "EntityCollectionPart(" + navigableRole.getFullPath() + ")@" + System.identityHashCode( this ); @@ -193,7 +205,7 @@ public EntityFetch generateFetch( final boolean added = creationState.registerVisitedAssociationKey( associationKey ); final TableGroup partTableGroup = resolveTableGroup( fetchablePath, creationState ); - final EntityFetchJoinedImpl fetch = new EntityFetchJoinedImpl( + final EntityFetch fetch = buildEntityFetchJoined( fetchParent, this, partTableGroup, @@ -208,6 +220,38 @@ public EntityFetch generateFetch( return fetch; } + // For Hibernate Reactive + protected EagerCollectionFetch buildEagerCollectionFetch( + NavigablePath fetchedPath, + PluralAttributeMapping fetchedAttribute, + TableGroup collectionTableGroup, + FetchParent fetchParent, + DomainResultCreationState creationState) { + return new EagerCollectionFetch( + fetchedPath, + fetchedAttribute, + collectionTableGroup, + fetchParent, + creationState + ); + } + + // For Hibernate Reactive + protected EntityFetch buildEntityFetchJoined( + FetchParent fetchParent, + AbstractEntityCollectionPart abstractEntityCollectionPart, + TableGroup partTableGroup, + NavigablePath fetchablePath, + DomainResultCreationState creationState) { + return new EntityFetchJoinedImpl( + fetchParent, + abstractEntityCollectionPart, + partTableGroup, + fetchablePath, + creationState + ); + } + protected abstract AssociationKey resolveFetchAssociationKey(); private TableGroup resolveTableGroup(NavigablePath fetchablePath, DomainResultCreationState creationState) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java index 08378bcda2..5b544600b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java @@ -49,6 +49,12 @@ public AbstractSingularAttributeMapping( this.propertyAccess = propertyAccess; } + // For Hibernate Reactive + protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping original ) { + super( original ); + this.propertyAccess = original.propertyAccess; + } + @Override public PropertyAccess getPropertyAccess() { return propertyAccess; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java index c21de11458..cafe354cd5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java @@ -57,6 +57,16 @@ public AbstractStateArrayContributorMapping( ); } + // For Hibernate Reactive + protected AbstractStateArrayContributorMapping(AbstractStateArrayContributorMapping original) { + super( original ); + this.attributeMetadata = original.attributeMetadata; + this.fetchTiming = original.fetchTiming; + this.fetchStyle = original.fetchStyle; + this.stateArrayPosition = original.stateArrayPosition; + } + + @Override public int getStateArrayPosition() { return stateArrayPosition; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 06c239a9ad..810cc97f95 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.SortedMap; import java.util.SortedSet; +import java.util.function.Function; import org.hibernate.FetchMode; import org.hibernate.MappingException; @@ -431,6 +432,33 @@ public static PluralAttributeMapping buildPluralAttributeMapping( CascadeStyle cascadeStyle, FetchMode fetchMode, MappingModelCreationProcess creationProcess) { + return buildPluralAttributeMapping( + attrName, + stateArrayPosition, + fetchableIndex, + bootProperty, + declaringType, + propertyAccess, + cascadeStyle, + fetchMode, + creationProcess, + Function.identity() + ); + } + + @SuppressWarnings("rawtypes") + public static PluralAttributeMapping buildPluralAttributeMapping( + String attrName, + int stateArrayPosition, + int fetchableIndex, + Property bootProperty, + ManagedMappingType declaringType, + PropertyAccess propertyAccess, + CascadeStyle cascadeStyle, + FetchMode fetchMode, + MappingModelCreationProcess creationProcess, + // For Hibernate Reactive + Function mappingConverter) { final Collection bootValueMapping = (Collection) bootProperty.getValue(); @@ -625,28 +653,33 @@ public static PluralAttributeMapping buildPluralAttributeMapping( sessionFactory ); - final PluralAttributeMappingImpl pluralAttributeMapping = new PluralAttributeMappingImpl( - attrName, - bootValueMapping, - propertyAccess, - attributeMetadata, - collectionMappingType, - stateArrayPosition, - fetchableIndex, - elementDescriptor, - indexDescriptor, - identifierDescriptor, - timing, - style, - cascadeStyle, - declaringType, - collectionDescriptor - ); + final PluralAttributeMappingImpl pluralAttributeMapping = mappingConverter + .apply( new PluralAttributeMappingImpl( + attrName, + bootValueMapping, + propertyAccess, + attributeMetadata, + collectionMappingType, + stateArrayPosition, + fetchableIndex, + elementDescriptor, + indexDescriptor, + identifierDescriptor, + timing, + style, + cascadeStyle, + declaringType, + collectionDescriptor + ) ); creationProcess.registerInitializationCallback( "PluralAttributeMapping(" + bootValueMapping.getRole() + ")#finishInitialization", () -> { - pluralAttributeMapping.finishInitialization( bootProperty, bootValueMapping, creationProcess ); + pluralAttributeMapping.finishInitialization( + bootProperty, + bootValueMapping, + creationProcess + ); return true; } ); @@ -1550,6 +1583,7 @@ public JavaType getMappedJavaType() { } } + // For Hibernate Reactive public static ToOneAttributeMapping buildSingularAssociationAttributeMapping( String attrName, NavigableRole navigableRole, @@ -1562,6 +1596,35 @@ public static ToOneAttributeMapping buildSingularAssociationAttributeMapping( PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) { + return buildSingularAssociationAttributeMapping( + attrName, + navigableRole, + stateArrayPosition, + fetchableIndex, + bootProperty, + declaringType, + declaringEntityPersister, + attrType, + propertyAccess, + cascadeStyle, + creationProcess, + Function.identity() + ); + } + + public static ToOneAttributeMapping buildSingularAssociationAttributeMapping( + String attrName, + NavigableRole navigableRole, + int stateArrayPosition, + int fetchableIndex, + Property bootProperty, + ManagedMappingType declaringType, + EntityPersister declaringEntityPersister, + EntityType attrType, + PropertyAccess propertyAccess, + CascadeStyle cascadeStyle, + MappingModelCreationProcess creationProcess, + Function mappingConverter) { if ( bootProperty.getValue() instanceof ToOne ) { final ToOne value = (ToOne) bootProperty.getValue(); final EntityPersister entityPersister = creationProcess.getEntityPersister( value.getReferencedEntityName() ); @@ -1614,7 +1677,7 @@ else if ( !lazy fetchTiming = FetchOptionsHelper.determineFetchTiming( fetchStyle, type, lazy, role, sessionFactory ); } - final ToOneAttributeMapping attributeMapping = new ToOneAttributeMapping( + final ToOneAttributeMapping attributeMapping = mappingConverter.apply( new ToOneAttributeMapping( attrName, navigableRole, stateArrayPosition, @@ -1627,7 +1690,7 @@ else if ( !lazy declaringType, declaringEntityPersister, propertyAccess - ); + ) ); creationProcess.registerForeignKeyPostInitCallbacks( "To-one key - " + navigableRole, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/OneToManyCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/OneToManyCollectionPart.java index 968bed8d9e..15948d82e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/OneToManyCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/OneToManyCollectionPart.java @@ -73,6 +73,12 @@ public OneToManyCollectionPart( } } + protected OneToManyCollectionPart(OneToManyCollectionPart original) { + super( original ); + this.mapKeyPropertyName = original.mapKeyPropertyName; + this.fetchAssociationKey = original.fetchAssociationKey; + } + @Override public Cardinality getCardinality() { return Cardinality.ONE_TO_MANY; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index 8fe858e22d..a08f233c41 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -190,16 +190,49 @@ public String getIndexPropertyName() { } }; + injectAttributeMapping( elementDescriptor, indexDescriptor, collectionDescriptor, this ); + } + + // For Hibernate Reactive + protected PluralAttributeMappingImpl(PluralAttributeMappingImpl original) { + super( original ); + this.propertyAccess = original.propertyAccess; + this.attributeMetadata = original.attributeMetadata; + this.collectionMappingType = original.collectionMappingType; + this.stateArrayPosition = original.stateArrayPosition; + this.elementDescriptor = original.elementDescriptor; + this.indexDescriptor = original.indexDescriptor; + this.identifierDescriptor = original.identifierDescriptor; + this.fetchTiming = original.fetchTiming; + this.fetchStyle = original.fetchStyle; + this.collectionDescriptor = original.collectionDescriptor; + this.referencedPropertyName = original.referencedPropertyName; + this.mapKeyPropertyName = original.mapKeyPropertyName; + this.bidirectionalAttributeName = original.bidirectionalAttributeName; + this.sqlAliasStem = original.sqlAliasStem; + this.separateCollectionTable = original.separateCollectionTable; + this.indexMetadata = original.indexMetadata; + this.fkDescriptor = original.fkDescriptor; + this.orderByFragment = original.orderByFragment; + this.manyToManyOrderByFragment = original.manyToManyOrderByFragment; + injectAttributeMapping( elementDescriptor, indexDescriptor, collectionDescriptor, this ); + } + + private static void injectAttributeMapping( + CollectionPart elementDescriptor, + CollectionPart indexDescriptor, + CollectionPersister collectionDescriptor, + PluralAttributeMapping mapping) { if ( collectionDescriptor instanceof Aware ) { - ( (Aware) collectionDescriptor ).injectAttributeMapping( this ); + ( (Aware) collectionDescriptor ).injectAttributeMapping( mapping ); } if ( elementDescriptor instanceof Aware ) { - ( (Aware) elementDescriptor ).injectAttributeMapping( this ); + ( (Aware) elementDescriptor ).injectAttributeMapping( mapping ); } if ( indexDescriptor instanceof Aware ) { - ( (Aware) indexDescriptor ).injectAttributeMapping( this ); + ( (Aware) indexDescriptor ).injectAttributeMapping( mapping ); } } @@ -405,7 +438,7 @@ public Fetch generateFetch( sqlAstCreationState ); - return new EagerCollectionFetch( + return buildEagerCollectionFetch( fetchablePath, this, collectionTableGroup, @@ -443,6 +476,40 @@ public Fetch generateFetch( } } + // For Hibernate Reactive + protected Fetch buildDelayedCollectionFetch( + NavigablePath fetchedPath, + PluralAttributeMapping fetchedAttribute, + FetchParent fetchParent, + DomainResult collectionKeyResult) { + return new DelayedCollectionFetch( fetchedPath, fetchedAttribute, fetchParent, collectionKeyResult ); + } + + // For Hibernate Reactive + protected Fetch buildSelectEagerCollectionFetch( + NavigablePath fetchedPath, + PluralAttributeMapping fetchedAttribute, + DomainResult collectionKeyDomainResult, + FetchParent fetchParent) { + return new SelectEagerCollectionFetch( fetchedPath, fetchedAttribute, collectionKeyDomainResult, fetchParent ); + } + + // For Hibernate Reactive + protected Fetch buildEagerCollectionFetch( + NavigablePath fetchedPath, + PluralAttributeMapping fetchedAttribute, + TableGroup collectionTableGroup, + FetchParent fetchParent, + DomainResultCreationState creationState) { + return new EagerCollectionFetch( + fetchedPath, + fetchedAttribute, + collectionTableGroup, + fetchParent, + creationState + ); + } + @Override public Fetch resolveCircularFetch( NavigablePath fetchablePath, @@ -481,7 +548,7 @@ private Fetch createSelectEagerCollectionFetch( else { collectionKeyDomainResult = null; } - return new SelectEagerCollectionFetch( fetchablePath, this, collectionKeyDomainResult, fetchParent ); + return buildSelectEagerCollectionFetch( fetchablePath, this, collectionKeyDomainResult, fetchParent ); } private TableGroup resolveCollectionTableGroup( @@ -531,7 +598,7 @@ private Fetch createDelayedCollectionFetch( creationState ); } - return new DelayedCollectionFetch( + return buildDelayedCollectionFetch( fetchablePath, this, fetchParent, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index 691e213fcb..ee6b4d01d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -157,32 +157,29 @@ public class Entity1 { private String identifyingColumnsTableExpression; private boolean canUseParentTableGroup; - protected ToOneAttributeMapping(ToOneAttributeMapping delegate) { - super( - delegate.getAttributeName(), - delegate.getStateArrayPosition(), - delegate.getFetchableKey(), - delegate.getAttributeMetadata(), - delegate.getMappedFetchOptions(), - delegate.getDeclaringType(), - delegate.getPropertyAccess() - ); - navigableRole = delegate.navigableRole; - isInternalLoadNullable = delegate.isInternalLoadNullable; - notFoundAction = delegate.notFoundAction; - unwrapProxy = delegate.unwrapProxy; - isOptional = delegate.isOptional; - entityMappingType = delegate.entityMappingType; - referencedPropertyName = delegate.referencedPropertyName; - targetKeyPropertyName = delegate.targetKeyPropertyName; - cardinality = delegate.cardinality; - bidirectionalAttributePath = delegate.bidirectionalAttributePath; - declaringTableGroupProducer = delegate.declaringTableGroupProducer; - isKeyTableNullable = delegate.isKeyTableNullable; - sqlAliasStem = delegate.sqlAliasStem; - targetKeyPropertyNames = delegate.targetKeyPropertyNames; - isNullable = delegate.isNullable; - foreignKeyDescriptor = delegate.foreignKeyDescriptor; + // For Hibernate Reactive + protected ToOneAttributeMapping(ToOneAttributeMapping original) { + super( original ); + navigableRole = original.navigableRole; + isInternalLoadNullable = original.isInternalLoadNullable; + notFoundAction = original.notFoundAction; + unwrapProxy = original.unwrapProxy; + isOptional = original.isOptional; + entityMappingType = original.entityMappingType; + referencedPropertyName = original.referencedPropertyName; + targetKeyPropertyName = original.targetKeyPropertyName; + cardinality = original.cardinality; + bidirectionalAttributePath = original.bidirectionalAttributePath; + declaringTableGroupProducer = original.declaringTableGroupProducer; + isKeyTableNullable = original.isKeyTableNullable; + sqlAliasStem = original.sqlAliasStem; + targetKeyPropertyNames = original.targetKeyPropertyNames; + isNullable = original.isNullable; + foreignKeyDescriptor = original.foreignKeyDescriptor; + sideNature = original.sideNature; + identifyingColumnsTableExpression = original.identifyingColumnsTableExpression; + canUseParentTableGroup = original.canUseParentTableGroup; + } public ToOneAttributeMapping( @@ -1186,7 +1183,7 @@ else if ( CollectionPart.Nature.fromNameExact( parentNavigablePath.getLocalName( final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess(); final TableGroup tableGroup = fromClauseAccess.getTableGroup( referencedNavigablePath ); fromClauseAccess.registerTableGroup( fetchablePath, tableGroup ); - return new EntityFetchJoinedImpl( + return buildEntityFetchJoined( fetchParent, this, tableGroup, @@ -1216,7 +1213,7 @@ else if ( CollectionPart.Nature.fromNameExact( parentNavigablePath.getLocalName( creationState ); if ( fetchTiming == FetchTiming.IMMEDIATE ) { - return new EntityFetchSelectImpl( + return buildEntityFetchSelect( fetchParent, this, fetchablePath, @@ -1226,7 +1223,7 @@ else if ( CollectionPart.Nature.fromNameExact( parentNavigablePath.getLocalName( ); } - return new EntityDelayedFetchImpl( + return buildEntityDelayedFetch( fetchParent, this, fetchablePath, @@ -1236,6 +1233,52 @@ else if ( CollectionPart.Nature.fromNameExact( parentNavigablePath.getLocalName( } } + // For Hibernate Reactive + protected EntityFetch buildEntityDelayedFetch( + FetchParent fetchParent, + ToOneAttributeMapping fetchedAttribute, + NavigablePath navigablePath, + DomainResult keyResult, + boolean selectByUniqueKey) { + return new EntityDelayedFetchImpl( fetchParent, fetchedAttribute, navigablePath, keyResult, selectByUniqueKey ); + } + + // For Hibernate Reactive + protected EntityFetch buildEntityFetchSelect( + FetchParent fetchParent, + ToOneAttributeMapping fetchedAttribute, + NavigablePath navigablePath, + DomainResult keyResult, + boolean selectByUniqueKey, + @SuppressWarnings("unused") DomainResultCreationState creationState) { + return new EntityFetchSelectImpl( + fetchParent, + fetchedAttribute, + navigablePath, + keyResult, + selectByUniqueKey, + creationState + ); + } + + // For Hibernate Reactive + protected EntityFetch buildEntityFetchJoined( + FetchParent fetchParent, + ToOneAttributeMapping toOneMapping, + TableGroup tableGroup, + DomainResult keyResult, + NavigablePath navigablePath, + DomainResultCreationState creationState) { + return new EntityFetchJoinedImpl( + fetchParent, + toOneMapping, + tableGroup, + keyResult, + navigablePath, + creationState + ); + } + private NavigablePath getReferencedNavigablePath( DomainResultCreationState creationState, NavigablePath parentNavigablePath) { @@ -1385,7 +1428,7 @@ else if ( notFoundAction != null ) { ); } - return new EntityFetchJoinedImpl( + return buildEntityFetchJoined( fetchParent, this, tableGroup, @@ -1443,7 +1486,7 @@ else if ( notFoundAction != null ) { // Consider all associations annotated with @NotFound as EAGER if ( fetchTiming == FetchTiming.IMMEDIATE || hasNotFoundAction() ) { - return new EntityFetchSelectImpl( + return buildEntityFetchSelect( fetchParent, this, fetchablePath, @@ -1453,7 +1496,7 @@ else if ( notFoundAction != null ) { ); } - return new EntityDelayedFetchImpl( + return buildEntityDelayedFetch( fetchParent, this, fetchablePath, 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 fa839b62e2..38a511927f 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 @@ -5420,7 +5420,7 @@ else if ( attrType instanceof CompositeType ) { dependantValue = ( (DependantValue) bootProperty.getValue() ); } - return MappingModelCreationHelper.buildEmbeddedAttributeMapping( + return buildEmbeddedAttributeMapping( attrName, stateArrayPosition, fetchableIndex, @@ -5437,7 +5437,7 @@ else if ( attrType instanceof CompositeType ) { ); } else if ( attrType instanceof CollectionType ) { - return MappingModelCreationHelper.buildPluralAttributeMapping( + return buildPluralAttributeMapping( attrName, stateArrayPosition, fetchableIndex, @@ -5450,7 +5450,7 @@ else if ( attrType instanceof CollectionType ) { ); } else if ( attrType instanceof EntityType ) { - return MappingModelCreationHelper.buildSingularAssociationAttributeMapping( + return buildSingularAssociationAttributeMapping( attrName, getNavigableRole().append( attrName ), stateArrayPosition, @@ -5470,6 +5470,90 @@ else if ( attrType instanceof EntityType ) { return null; } + // For Hibernate Reactive + protected EmbeddedAttributeMapping buildEmbeddedAttributeMapping( + String attrName, + int stateArrayPosition, + int fetchableIndex, + Property bootProperty, + DependantValue dependantValue, + int dependantColumnIndex, + ManagedMappingType declaringType, + CompositeType attrType, + String tableExpression, + String[] rootTableKeyColumnNames, + PropertyAccess propertyAccess, + CascadeStyle cascadeStyle, + MappingModelCreationProcess creationProcess) { + return MappingModelCreationHelper.buildEmbeddedAttributeMapping( + attrName, + stateArrayPosition, + fetchableIndex, + bootProperty, + dependantValue, + dependantColumnIndex, + declaringType, + attrType, + tableExpression, + rootTableKeyColumnNames, + propertyAccess, + cascadeStyle, + creationProcess + ); + } + + // For Hibernate Reactive + protected AttributeMapping buildSingularAssociationAttributeMapping( + String attrName, + NavigableRole navigableRole, + int stateArrayPosition, + int fetchableIndex, + Property bootProperty, + ManagedMappingType declaringType, + EntityPersister declaringEntityPersister, + EntityType attrType, + PropertyAccess propertyAccess, + CascadeStyle cascadeStyle, + MappingModelCreationProcess creationProcess) { + return MappingModelCreationHelper.buildSingularAssociationAttributeMapping( + attrName, + navigableRole, + stateArrayPosition, + fetchableIndex, + bootProperty, + declaringType, + declaringEntityPersister, + attrType, + propertyAccess, + cascadeStyle, + creationProcess + ); + } + + // For Hibernate Reactive + protected AttributeMapping buildPluralAttributeMapping( + String attrName, + int stateArrayPosition, + int fetchableIndex, + Property bootProperty, + ManagedMappingType declaringType, + PropertyAccess propertyAccess, + CascadeStyle cascadeStyle, + FetchMode fetchMode, + MappingModelCreationProcess creationProcess) { + return MappingModelCreationHelper.buildPluralAttributeMapping( + attrName, + stateArrayPosition, + fetchableIndex, + bootProperty, + declaringType, + propertyAccess, + cascadeStyle, + fetchMode, + creationProcess + ); + } + @Override public JavaType getMappedJavaType() { return javaType; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityFetchJoinedImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityFetchJoinedImpl.java index 28c9e80b90..e0ea73fe45 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityFetchJoinedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityFetchJoinedImpl.java @@ -6,6 +6,7 @@ */ package org.hibernate.sql.results.graph.entity.internal; +import org.hibernate.LockMode; import org.hibernate.annotations.NotFoundAction; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.internal.EntityCollectionPart; @@ -15,10 +16,14 @@ import org.hibernate.sql.results.graph.AssemblerCreationState; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.FetchParentAccess; +import org.hibernate.sql.results.graph.Initializer; import org.hibernate.sql.results.graph.entity.AbstractNonLazyEntityFetch; import org.hibernate.sql.results.graph.entity.EntityInitializer; +import org.hibernate.sql.results.graph.entity.EntityResultGraphNode; +import org.hibernate.sql.results.graph.entity.EntityValuedFetchable; /** * @author Andrea Boriero @@ -74,6 +79,15 @@ public EntityFetchJoinedImpl( this.entityResult.afterInitialize( this, creationState ); } + // For Hibernate Reactive + protected EntityFetchJoinedImpl(EntityFetchJoinedImpl original ) { + super( original.getFetchParent(), original.getReferencedModePart(), original.getNavigablePath() ); + this.entityResult = original.entityResult; + this.keyResult = original.keyResult; + this.notFoundAction = original.notFoundAction; + this.sourceAlias = original.sourceAlias; + } + @Override protected EntityInitializer getEntityInitializer( FetchParentAccess parentAccess, @@ -81,7 +95,7 @@ protected EntityInitializer getEntityInitializer( return creationState.resolveInitializer( getNavigablePath(), getReferencedModePart(), - () -> new EntityJoinedFetchInitializer( + () -> buildEntityJoinedFetchInitializer( entityResult, getReferencedModePart(), getNavigablePath(), @@ -95,6 +109,30 @@ protected EntityInitializer getEntityInitializer( ).asEntityInitializer(); } + // For Hibernate Reactive + protected Initializer buildEntityJoinedFetchInitializer( + EntityResultGraphNode resultDescriptor, + EntityValuedFetchable referencedFetchable, + NavigablePath navigablePath, + LockMode lockMode, + NotFoundAction notFoundAction, + DomainResult keyResult, + Fetch identifierFetch, + Fetch discriminatorFetch, + AssemblerCreationState creationState) { + return new EntityJoinedFetchInitializer( + resultDescriptor, + referencedFetchable, + navigablePath, + lockMode, + notFoundAction, + keyResult, + identifierFetch, + discriminatorFetch, + creationState + ); + } + @Override public FetchTiming getTiming() { return FetchTiming.IMMEDIATE;