diff --git a/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java index 4e0b0cdb0d..9e7ab74466 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java @@ -29,7 +29,6 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.mapping.EntityMappingType; -import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.query.NavigablePath; @@ -161,7 +160,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr ); } - final String ownerTableAlias = fullPropertyPath.substring( 0, firstDot - 1 ); + final String ownerTableAlias = fullPropertyPath.substring( 0, firstDot ); final String propertyPath = fullPropertyPath.substring( firstDot + 1 ); final String tableAlias = jaxbHbmJoin.getAlias(); @@ -394,7 +393,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr ); } - final Map fetchDescriptorMap = new HashMap<>(); + final Map fetchDescriptorMap = new HashMap<>(); propertyFetchDescriptors.forEach( hbmFetchDescriptor -> fetchDescriptorMap.put( hbmFetchDescriptor.getFetchablePath(), @@ -403,6 +402,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr ); return new ResultMementoEntityStandard( + tableAlias, entityDescriptor, lockMode, discriminatorMemento, @@ -462,7 +462,10 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr (fetchableName, joinDescriptor) -> { final boolean added = processedFetchableNames.add( fetchableName ); - if ( ! added ) { + if ( added ) { + propertyFetchDescriptors.add( joinDescriptor ); + } + else { // the fetch is most likely more complete of a mapping so replace the original for ( int i = 0; i < propertyFetchDescriptors.size(); i++ ) { final HbmFetchDescriptor propertyFetchDescriptor = propertyFetchDescriptors.get( i ); @@ -587,7 +590,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr ); } - this.ownerTableAlias = fullPropertyPath.substring( 0, firstDot - 1 ); + this.ownerTableAlias = fullPropertyPath.substring( 0, firstDot ); this.propertyPath = fullPropertyPath.substring( firstDot + 1 ); this.tableAlias = hbmJoinReturn.getAlias(); @@ -628,9 +631,20 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr applyFetchJoins( joinDescriptorsAccess, tableAlias, propertyFetchDescriptors ); + final Map fetchDescriptorMap = new HashMap<>(); + propertyFetchDescriptors.forEach( + hbmFetchDescriptor -> fetchDescriptorMap.put( + hbmFetchDescriptor.getFetchablePath(), + hbmFetchDescriptor.resolve( resolutionContext ) + ) + ); memento = new FetchMementoHbmStandard( thisAsParentMemento.getNavigablePath(), + ownerTableAlias, + tableAlias, + lockMode, thisAsParentMemento, + fetchDescriptorMap, (Fetchable) thisAsParentMemento.getFetchableContainer() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/FetchMementoHbmStandard.java b/hibernate-core/src/main/java/org/hibernate/query/internal/FetchMementoHbmStandard.java index 0312dee341..8cf150d335 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/FetchMementoHbmStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/FetchMementoHbmStandard.java @@ -6,34 +6,50 @@ */ package org.hibernate.query.internal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; +import org.hibernate.LockMode; import org.hibernate.query.NavigablePath; import org.hibernate.query.named.FetchMemento; import org.hibernate.query.results.FetchBuilder; +import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy; import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.FetchableContainer; /** * @author Steve Ebersole */ -public class FetchMementoHbmStandard implements FetchMemento { +public class FetchMementoHbmStandard implements FetchMemento, FetchMemento.Parent { public interface FetchParentMemento { NavigablePath getNavigablePath(); FetchableContainer getFetchableContainer(); } private final NavigablePath navigablePath; - + private final String ownerTableAlias; + private final String tableAlias; + private final LockMode lockMode; private final FetchParentMemento parent; + private final Map fetchMementoMap; private final Fetchable fetchable; public FetchMementoHbmStandard( NavigablePath navigablePath, + String ownerTableAlias, + String tableAlias, + LockMode lockMode, FetchParentMemento parent, + Map fetchMementoMap, Fetchable fetchable) { this.navigablePath = navigablePath; + this.ownerTableAlias = ownerTableAlias; + this.tableAlias = tableAlias; + this.lockMode = lockMode; this.parent = parent; + this.fetchMementoMap = fetchMementoMap; this.fetchable = fetchable; } @@ -47,6 +63,20 @@ public class FetchMementoHbmStandard implements FetchMemento { Parent parent, Consumer querySpaceConsumer, ResultSetMappingResolutionContext context) { - return null; + final Map fetchBuilderMap = new HashMap<>(); + + fetchMementoMap.forEach( + (attrName, fetchMemento) -> fetchBuilderMap.put( + attrName, + fetchMemento.resolve(this, querySpaceConsumer, context ) + ) + ); + return new DynamicFetchBuilderLegacy( + tableAlias, + ownerTableAlias, + fetchable.getFetchableName(), + new ArrayList<>(), + fetchBuilderMap + ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoEntityStandard.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoEntityStandard.java index 3f079b0cc9..6552b69859 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoEntityStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoEntityStandard.java @@ -26,6 +26,7 @@ import org.hibernate.query.results.complete.CompleteResultBuilderEntityStandard; * @author Steve Ebersole */ public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMemento.Parent { + private final String tableAlias; private final NavigablePath navigablePath; private final EntityMappingType entityDescriptor; private final LockMode lockMode; @@ -33,10 +34,12 @@ public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMe private final Map fetchMementoMap; public ResultMementoEntityStandard( + String tableAlias, EntityMappingType entityDescriptor, LockMode lockMode, ResultMementoBasic discriminatorMemento, Map fetchMementoMap) { + this.tableAlias = tableAlias; this.navigablePath = new NavigablePath( entityDescriptor.getEntityName() ); this.entityDescriptor = entityDescriptor; this.lockMode = lockMode; @@ -72,6 +75,7 @@ public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMe ); return new CompleteResultBuilderEntityStandard( + tableAlias, navigablePath, entityDescriptor, lockMode, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/Builders.java b/hibernate-core/src/main/java/org/hibernate/query/results/Builders.java index 708b247841..3817d4eae1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/Builders.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/Builders.java @@ -239,7 +239,7 @@ public class Builders { } public static DynamicFetchBuilderLegacy fetch(String tableAlias, String ownerTableAlias, String joinPropertyName) { - return new DynamicFetchBuilderLegacy( tableAlias, ownerTableAlias, joinPropertyName, null ); + return new DynamicFetchBuilderLegacy( tableAlias, ownerTableAlias, joinPropertyName, null, null ); } public static ResultBuilder implicitEntityResultBuilder( diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/FetchBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/results/FetchBuilder.java index ea864d08cc..732471b256 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/FetchBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/FetchBuilder.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.results; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import org.hibernate.Incubating; @@ -31,4 +32,7 @@ public interface FetchBuilder { NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction legacyFetchResolver, DomainResultCreationState domainResultCreationState); + + default void visitFetchBuilders(BiConsumer consumer) { + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/ResultBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/results/ResultBuilder.java index 0d7c8ce26f..95ce232279 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/ResultBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/ResultBuilder.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.results; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import org.hibernate.Incubating; @@ -27,4 +28,7 @@ public interface ResultBuilder { int resultPosition, BiFunction legacyFetchResolver, DomainResultCreationState domainResultCreationState); + + default void visitFetchBuilders(BiConsumer consumer) { + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java index df97531a0a..6d1bc736f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java @@ -7,6 +7,7 @@ package org.hibernate.query.results.complete; import java.util.HashMap; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import org.hibernate.LockMode; @@ -118,4 +119,9 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti impl.popExplicitFetchMementoResolver(); } } + + @Override + public void visitFetchBuilders(BiConsumer consumer) { + explicitFetchBuilderMap.forEach( consumer ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java index dbeba9a5ce..dba602a1f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java @@ -7,10 +7,12 @@ package org.hibernate.query.results.complete; import java.util.HashMap; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import org.hibernate.LockMode; import org.hibernate.metamodel.mapping.EntityMappingType; +import org.hibernate.query.NativeQuery; import org.hibernate.query.NavigablePath; import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.FetchBuilder; @@ -25,7 +27,8 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; /** * @author Steve Ebersole */ -public class CompleteResultBuilderEntityStandard implements CompleteResultBuilderEntityValued { +public class CompleteResultBuilderEntityStandard implements CompleteResultBuilderEntityValued, NativeQuery.RootReturn { + private final String tableAlias; private final NavigablePath navigablePath; private final EntityMappingType entityDescriptor; private final LockMode lockMode; @@ -33,11 +36,13 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde private final HashMap explicitFetchBuilderMap; public CompleteResultBuilderEntityStandard( + String tableAlias, NavigablePath navigablePath, EntityMappingType entityDescriptor, LockMode lockMode, ResultBuilderBasicValued discriminatorResultBuilder, HashMap explicitFetchBuilderMap) { + this.tableAlias = tableAlias; this.navigablePath = navigablePath; this.entityDescriptor = entityDescriptor; this.lockMode = lockMode; @@ -55,6 +60,46 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde return entityDescriptor; } + @Override + public String getTableAlias() { + return tableAlias; + } + + @Override + public String getDiscriminatorAlias() { + return null; + } + + @Override + public EntityMappingType getEntityMapping() { + return entityDescriptor; + } + + @Override + public NativeQuery.RootReturn setLockMode(LockMode lockMode) { + throw new UnsupportedOperationException(); + } + + @Override + public NativeQuery.RootReturn addIdColumnAliases(String... aliases) { + throw new UnsupportedOperationException(); + } + + @Override + public NativeQuery.RootReturn setDiscriminatorAlias(String columnAlias) { + throw new UnsupportedOperationException(); + } + + @Override + public NativeQuery.RootReturn addProperty(String propertyName, String columnAlias) { + throw new UnsupportedOperationException(); + } + + @Override + public NativeQuery.ReturnProperty addProperty(String propertyName) { + throw new UnsupportedOperationException(); + } + @Override public EntityResult buildResult( JdbcValuesMetadata jdbcResultsMetadata, @@ -107,4 +152,9 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde impl.popExplicitFetchMementoResolver(); } } + + @Override + public void visitFetchBuilders(BiConsumer consumer) { + explicitFetchBuilderMap.forEach( consumer ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/AbstractFetchBuilderContainer.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/AbstractFetchBuilderContainer.java index 8156430120..83f5950ec8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/AbstractFetchBuilderContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/AbstractFetchBuilderContainer.java @@ -74,6 +74,9 @@ public abstract class AbstractFetchBuilderContainer(); + } fetchBuilderMap.put( propertyName, fetchBuilder ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java index d2692af49f..43e3b541ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java @@ -7,6 +7,8 @@ package org.hibernate.query.results.dynamic; import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import org.hibernate.LockMode; @@ -18,6 +20,7 @@ import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.query.NativeQuery; import org.hibernate.query.NavigablePath; import org.hibernate.query.results.DomainResultCreationStateImpl; +import org.hibernate.query.results.FetchBuilder; import org.hibernate.query.results.ResultsHelper; import org.hibernate.query.results.SqlSelectionImpl; import org.hibernate.sql.ast.SqlAstJoinType; @@ -46,17 +49,20 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue private final String fetchableName; private final List columnNames; + private final Map fetchBuilderMap; private final DynamicResultBuilderEntityStandard resultBuilderEntity; public DynamicFetchBuilderLegacy( String tableAlias, String ownerTableAlias, String fetchableName, - List columnNames) { + List columnNames, + Map fetchBuilderMap) { this.tableAlias = tableAlias; this.ownerTableAlias = ownerTableAlias; this.fetchableName = fetchableName; this.columnNames = columnNames; + this.fetchBuilderMap = fetchBuilderMap; this.resultBuilderEntity = null; } @@ -65,11 +71,13 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue String ownerTableAlias, String fetchableName, List columnNames, + Map fetchBuilderMap, DynamicResultBuilderEntityStandard resultBuilderEntity) { this.tableAlias = tableAlias; this.ownerTableAlias = ownerTableAlias; this.fetchableName = fetchableName; this.columnNames = columnNames; + this.fetchBuilderMap = fetchBuilderMap; this.resultBuilderEntity = resultBuilderEntity; } @@ -199,4 +207,9 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue public NativeQuery.ReturnProperty addProperty(String propertyName) { return null; } + + @Override + public void visitFetchBuilders(BiConsumer consumer) { + fetchBuilderMap.forEach( consumer ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java index 6709c94b55..0d27b1a4d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java @@ -75,7 +75,7 @@ public class DynamicFetchBuilderStandard state -> { final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); final int valuesArrayPosition = resultSetPosition - 1; - return new SqlSelectionImpl( valuesArrayPosition, (BasicValuedMapping) selectableMapping ); + return new SqlSelectionImpl( valuesArrayPosition, selectableMapping.getJdbcMapping() ); } ), selectableMapping.getJdbcMapping().getMappedJavaTypeDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEmbeddable.java index 829eed989d..235ca5c81c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEmbeddable.java @@ -8,6 +8,7 @@ package org.hibernate.query.results.implicit; import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -120,4 +121,9 @@ public class ImplicitFetchBuilderEmbeddable implements ImplicitFetchBuilder { public String toString() { return "ImplicitFetchBuilderEmbeddable(" + fetchPath + ")"; } + + @Override + public void visitFetchBuilders(BiConsumer consumer) { + fetchBuilders.forEach( (k, v) -> consumer.accept( k.getUnaliasedLocalName(), v ) ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java index ad685a5913..5b47d16d9a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java @@ -9,6 +9,7 @@ package org.hibernate.query.results.implicit; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -120,6 +121,11 @@ public class ImplicitFetchBuilderEntity implements ImplicitFetchBuilder { return fetch; } + @Override + public void visitFetchBuilders(BiConsumer consumer) { + fetchBuilders.forEach( (k, v) -> consumer.accept( k.getUnaliasedLocalName(), v ) ); + } + @Override public String toString() { return "ImplicitFetchBuilderEntity(" + fetchPath + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java index 6b1ea96073..db9a5ea524 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java @@ -29,6 +29,7 @@ import org.hibernate.persister.entity.Joinable; import org.hibernate.persister.entity.SQLLoadable; import org.hibernate.query.NativeQuery; import org.hibernate.query.NavigablePath; +import org.hibernate.query.results.FetchBuilder; import org.hibernate.query.results.ResultSetMapping; import org.hibernate.query.results.ResultSetMappingImpl; import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy; @@ -104,6 +105,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { if ( resultBuilder instanceof NativeQuery.RootReturn ) { final NativeQuery.RootReturn rootReturn = (NativeQuery.RootReturn) resultBuilder; alias2Return.put( rootReturn.getTableAlias(), rootReturn ); + resultBuilder.visitFetchBuilders( this::processFetchBuilder ); } } ); @@ -122,6 +124,18 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { return this; } + private void processFetchBuilder(String attributeName, FetchBuilder fetchBuilder) { + if ( fetchBuilder instanceof DynamicFetchBuilderLegacy ) { + resultSetMapping.addLegacyFetchBuilder( (DynamicFetchBuilderLegacy) fetchBuilder ); + } + else if ( fetchBuilder instanceof NativeQuery.FetchReturn ) { + final NativeQuery.FetchReturn fetchReturn = (NativeQuery.FetchReturn) fetchBuilder; + alias2Return.put( fetchReturn.getTableAlias(), fetchReturn ); + alias2OwnerAlias.put( fetchReturn.getTableAlias(), fetchReturn.getOwnerAlias() ); + } + fetchBuilder.visitFetchBuilders( this::processFetchBuilder ); + } + public ResultSetMapping generateResultMapping(boolean queryHadAliases) { if ( !queryHadAliases ) { return this.resultSetMapping; @@ -200,7 +214,15 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { columnNames = Collections.emptyList(); } else { - columnNames = Arrays.asList( collectionPersister.getKeyColumnAliases( suffix ) ); + final String collectionSuffix = alias2CollectionSuffix.get( fetchBuilder.getTableAlias() ); + final String[] keyColumnAliases = collectionPersister.getKeyColumnAliases( collectionSuffix ); + columnNames = Arrays.asList( keyColumnAliases ); + if ( collectionPersister.hasIndex() ) { + resultBuilderEntity.addProperty( + "{key}", // That's what BasicValuedCollectionPart returns.. + collectionPersister.getIndexColumnAliases( collectionSuffix ) + ); + } } } else { @@ -213,6 +235,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { fetchBuilder.getOwnerAlias(), fetchBuilder.getFetchableName(), columnNames, + Collections.emptyMap(), resultBuilderEntity ) ); @@ -256,8 +279,12 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { navigablePath ); - resultBuilderEntity.addIdColumnAliases( loadable.getIdentifierAliases( suffix ) ); + final String[] identifierAliases = loadable.getIdentifierAliases( suffix ); + resultBuilderEntity.addIdColumnAliases( identifierAliases ); resultBuilderEntity.setDiscriminatorAlias( loadable.getDiscriminatorAlias( suffix ) ); + if ( loadable.hasIdentifierProperty() ) { + resultBuilderEntity.addProperty( loadable.getIdentifierPropertyName(), identifierAliases ); + } for ( String propertyName : loadable.getPropertyNames() ) { final String[] columnAliases = loadable.getSubclassPropertyColumnAliases( @@ -384,7 +411,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext { // If this return's alias has not been processed yet, do so before further processing of this return if ( !alias2Persister.containsKey( ownerAlias ) ) { - processReturn( alias2Return.get(ownerAlias) ); + processReturn( alias2Return.get( ownerAlias ) ); } SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Championship.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Championship.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Championship.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Championship.java index e59bd4f5de..d8680ac106 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Championship.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Championship.java @@ -1,4 +1,4 @@ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.ArrayList; import java.util.List; diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.hbm.xml similarity index 88% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.hbm.xml index b8680a89a1..2292e45e27 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.hbm.xml @@ -1,26 +1,26 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.java index 1ddb0547e1..c3ca332416 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Child.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Child.java @@ -1,42 +1,42 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.extralazy; - - - -public class Child { - - private String id; - - private Parent parent; - - private String firstName; - - public void setParent(Parent parent) { - this.parent = parent; - } - - public Parent getParent() { - return parent; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getFirstName() { - return firstName; - } - - public void setId(String id) { - this.id = id; - } - - public String getId() { - return id; - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.extralazy; + + + +public class Child { + + private String id; + + private Parent parent; + + private String firstName; + + public void setParent(Parent parent) { + this.parent = parent; + } + + public Parent getParent() { + return parent; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getFirstName() { + return firstName; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Document.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Document.java old mode 100755 new mode 100644 similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Document.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Document.java index 39b24f2052..1eb5bb43b5 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Document.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Document.java @@ -6,7 +6,7 @@ */ //$Id: Document.java 7635 2005-07-24 23:04:30Z oneovthafew $ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; public class Document { diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyCollectionConsistencyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyCollectionConsistencyTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyCollectionConsistencyTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyCollectionConsistencyTest.java index 0a95285028..79646845c1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyCollectionConsistencyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyCollectionConsistencyTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.DomainModel; @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ @DomainModel( xmlMappings = { - "org/hibernate/test/extralazy/UserGroup.hbm.xml" + "org/hibernate/orm/test/extralazy/UserGroup.hbm.xml" } ) @SessionFactory diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyTest.java old mode 100755 new mode 100644 similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyTest.java index 477e4f96d7..381d2af7d6 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/ExtraLazyTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.List; import java.util.Map; @@ -36,9 +36,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; annotatedClasses = { School.class, Student.class, Championship.class }, xmlMappings = { - "org/hibernate/test/extralazy/UserGroup.hbm.xml", - "org/hibernate/test/extralazy/Parent.hbm.xml", - "org/hibernate/test/extralazy/Child.hbm.xml" + "org/hibernate/orm/test/extralazy/UserGroup.hbm.xml", + "org/hibernate/orm/test/extralazy/Parent.hbm.xml", + "org/hibernate/orm/test/extralazy/Child.hbm.xml" } ) @SessionFactory @@ -269,7 +269,7 @@ public class ExtraLazyTest { session.persist( turin ); session.flush(); session.clear(); - List results = session.getNamedQuery( "userData" ).setParameter( "uname", "%in" ).list(); + List results = session.getNamedQuery( "userSessionData" ).setParameter( "uname", "%in" ).list(); assertThat( results.size(), is( 2 ) ); gavin = (User) results.get( 0 ); assertThat( gavin.getName(), is( "gavin" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Group.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Group.java old mode 100755 new mode 100644 similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Group.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Group.java index f735bbaf63..40bd3366a6 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Group.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Group.java @@ -6,7 +6,7 @@ */ //$Id: Group.java 7628 2005-07-24 06:55:01Z oneovthafew $ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.HashMap; import java.util.Map; diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.hbm.xml similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.hbm.xml index 5688f0eb5d..f0ca4e074e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.hbm.xml @@ -1,27 +1,27 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.java index 12e0124f46..3e865fbf88 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Parent.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Parent.java @@ -1,35 +1,35 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.extralazy; - -import java.util.HashMap; -import java.util.Map; - - - -public class Parent { - - private String id; - - private Map children = new HashMap (); - - public void setChildren(Map children) { - this.children = children; - } - - public Map getChildren() { - return children; - } - - public void setId(String id) { - this.id = id; - } - - public String getId() { - return id; - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.extralazy; + +import java.util.HashMap; +import java.util.Map; + + + +public class Parent { + + private String id; + + private Map children = new HashMap (); + + public void setChildren(Map children) { + this.children = children; + } + + public Map getChildren() { + return children; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/School.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/School.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/School.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/School.java index faf307da80..d42b4e46e4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/School.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/School.java @@ -1,4 +1,4 @@ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.HashMap; import java.util.HashSet; diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/SessionAttribute.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/SessionAttribute.java old mode 100755 new mode 100644 similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/SessionAttribute.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/SessionAttribute.java index f450cabb0a..2932d62b6a --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/SessionAttribute.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/SessionAttribute.java @@ -6,7 +6,7 @@ */ //$Id: SessionAttribute.java 7628 2005-07-24 06:55:01Z oneovthafew $ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Student.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Student.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/Student.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Student.java index ea21c3e410..d45026af8a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/Student.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/Student.java @@ -1,4 +1,4 @@ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.Objects; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/User.java b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/User.java old mode 100755 new mode 100644 similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/User.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/User.java index 207c7ee027..6336501da7 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/User.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/User.java @@ -6,7 +6,7 @@ */ //$Id: User.java 7635 2005-07-24 23:04:30Z oneovthafew $ -package org.hibernate.test.extralazy; +package org.hibernate.orm.test.extralazy; import java.util.HashMap; import java.util.HashSet; import java.util.Map; diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/UserGroup.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/UserGroup.hbm.xml old mode 100755 new mode 100644 similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/extralazy/UserGroup.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/UserGroup.hbm.xml index 6f893650ea..1ed00cf0d2 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/UserGroup.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/extralazy/UserGroup.hbm.xml @@ -13,7 +13,7 @@ --> - + @@ -67,7 +67,6 @@ from users u join session_attributes s on lower(s.userName) = lower(u.name) where u.name like :uname - - +