From 1382929311e2d676e10f591fd6c58ee93c2c5549 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 29 Mar 2023 12:43:06 +0200 Subject: [PATCH] HHH-16349 Correct entity valued path selectable expansion --- .../internal/EntityValuedPathInterpretation.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java index d5a9800b24..966731568c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java @@ -42,7 +42,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.update.Assignable; import org.hibernate.sql.results.graph.DomainResultCreationState; -import org.hibernate.type.spi.TypeConfiguration; +import org.hibernate.sql.results.graph.Fetchable; public class EntityValuedPathInterpretation extends AbstractSqmPathInterpretation implements SqlTupleContainer, Assignable { @@ -296,11 +296,13 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta final Expression sqlExpression; if ( resultModelPart == null ) { + // Expand to all columns of the entity mapping type, as we already did for the selection final EntityMappingType entityMappingType = mapping.getEntityMappingType(); final EntityIdentifierMapping identifierMapping = entityMappingType.getIdentifierMapping(); final EntityDiscriminatorMapping discriminatorMapping = entityMappingType.getDiscriminatorMapping(); + final int numberOfFetchables = entityMappingType.getNumberOfFetchables(); final List expressions = new ArrayList<>( - entityMappingType.getJdbcTypeCount() + identifierMapping.getJdbcTypeCount() + numberOfFetchables + identifierMapping.getJdbcTypeCount() + ( discriminatorMapping == null ? 0 : 1 ) ); final TableGroup parentTableGroup = tableGroup; @@ -318,7 +320,12 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta if ( discriminatorMapping != null ) { discriminatorMapping.forEachSelectable( selectableConsumer ); } - entityMappingType.forEachSelectable( selectableConsumer ); + for ( int i = 0; i < numberOfFetchables; i++ ) { + final Fetchable fetchable = entityMappingType.getFetchable( i ); + if ( fetchable.isSelectable() ) { + fetchable.forEachSelectable( selectableConsumer ); + } + } sqlExpression = new SqlTuple( expressions, entityMappingType ); } else {