HHH-18720 Type check on select columns in union all gives SemanticException when there is a null column
This commit is contained in:
parent
8e27a8d185
commit
58254e585c
|
@ -166,7 +166,8 @@ public class SqmQueryGroup<T> extends SqmQueryPart<T> implements JpaQueryGroup<T
|
|||
for ( int j = 0; j < firstSelectionSize; j++ ) {
|
||||
final SqmTypedNode<?> firstSqmSelection = typedNodes.get( j );
|
||||
final JavaType<?> firstJavaType = firstSqmSelection.getNodeJavaType();
|
||||
if ( firstJavaType != selections.get( j ).getNodeJavaType() ) {
|
||||
final JavaType<?> nodeJavaType = selections.get( j ).getNodeJavaType();
|
||||
if ( nodeJavaType != null && firstJavaType != null && firstJavaType != nodeJavaType ) {
|
||||
throw new SemanticException(
|
||||
"Select items of the same index must have the same java type across all query parts"
|
||||
);
|
||||
|
|
|
@ -7,9 +7,15 @@ package org.hibernate.sql.results.jdbc.internal;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.query.results.ResultSetMapping;
|
||||
import org.hibernate.query.results.ResultSetMappingImpl;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.select.QueryGroup;
|
||||
import org.hibernate.sql.ast.tree.select.QueryPart;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducer;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducerProvider;
|
||||
import org.hibernate.type.descriptor.jdbc.NullJdbcType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Standard JdbcValuesMappingProducerProvider implementation
|
||||
|
@ -26,10 +32,19 @@ public class JdbcValuesMappingProducerProviderStandard implements JdbcValuesMapp
|
|||
public JdbcValuesMappingProducer buildMappingProducer(
|
||||
SelectStatement sqlAst,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
return new JdbcValuesMappingProducerStandard(
|
||||
sqlAst.getQuerySpec().getSelectClause().getSqlSelections(),
|
||||
sqlAst.getDomainResultDescriptors()
|
||||
);
|
||||
return new JdbcValuesMappingProducerStandard( getSelections( sqlAst ), sqlAst.getDomainResultDescriptors() );
|
||||
}
|
||||
|
||||
private static List<SqlSelection> getSelections(SelectStatement selectStatement) {
|
||||
if ( selectStatement.getQueryPart() instanceof QueryGroup queryGroup ) {
|
||||
for ( QueryPart queryPart : queryGroup.getQueryParts() ) {
|
||||
if ( !(queryPart.getFirstQuerySpec().getSelectClause().getSqlSelections()
|
||||
.get( 0 ).getExpressionType().getSingleJdbcMapping().getJdbcType() instanceof NullJdbcType) ) {
|
||||
return queryPart.getFirstQuerySpec().getSelectClause().getSqlSelections();
|
||||
}
|
||||
}
|
||||
}
|
||||
return selectStatement.getQuerySpec().getSelectClause().getSqlSelections();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue