diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlSelection.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlSelection.java index 7a7c140075..a051969b20 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlSelection.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlSelection.java @@ -7,6 +7,7 @@ package org.hibernate.sql.ast.spi; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; import org.hibernate.sql.results.jdbc.spi.RowProcessingState; import org.hibernate.sql.ast.SqlAstWalker; @@ -45,6 +46,11 @@ public interface SqlSelection { return getValuesArrayPosition() + 1; } + /** + * Get the type of the expression + */ + MappingModelExpressable getExpressionType(); + void accept(SqlAstWalker sqlAstWalker); default void prepare(JdbcValuesMetadata jdbcResultsMetadata, SessionFactoryImplementor sessionFactory) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java index c02b407501..2868eabff3 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java @@ -25,7 +25,6 @@ import org.hibernate.sql.ast.tree.predicate.PredicateContainer; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.basic.BasicResult; -import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; @@ -122,15 +121,14 @@ public class QuerySpec implements SqlAstNode, PredicateContainer, Expression, Ct @Override public MappingModelExpressable getExpressionType() { SqlSelection first = selectClause.getSqlSelections().get(0); - return ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType(); + return first.getExpressionType(); } @Override public void applySqlSelections(DomainResultCreationState creationState) { SqlSelection first = selectClause.getSqlSelections().get(0); TypeConfiguration typeConfiguration = creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration(); - JavaTypeDescriptor descriptor = ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType() - .getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor(); + JavaTypeDescriptor descriptor = first.getExpressionType().getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor(); creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, descriptor, @@ -142,8 +140,7 @@ public class QuerySpec implements SqlAstNode, PredicateContainer, Expression, Ct public DomainResult createDomainResult(String resultVariable, DomainResultCreationState creationState) { SqlSelection first = selectClause.getSqlSelections().get(0); TypeConfiguration typeConfiguration = creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration(); - JavaTypeDescriptor descriptor = ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType() - .getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor(); + JavaTypeDescriptor descriptor = first.getExpressionType().getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor(); final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver(); final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java index 844d43935a..ffc4c84126 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java @@ -6,6 +6,7 @@ */ package org.hibernate.sql.results.internal; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.mapping.SqlExpressable; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.spi.SqlSelection; @@ -65,6 +66,11 @@ public class SqlSelectionImpl implements SqlSelection { return valuesArrayPosition; } + @Override + public MappingModelExpressable getExpressionType() { + return getWrappedSqlExpression().getExpressionType(); + } + @Override public void accept(SqlAstWalker interpreter) { sqlExpression.accept( interpreter );