diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 27e8ccc805..59e49e0edb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -264,6 +264,7 @@ import static org.hibernate.query.sqm.TemporalUnit.TIMEZONE_HOUR; import static org.hibernate.query.sqm.TemporalUnit.TIMEZONE_MINUTE; import static org.hibernate.query.sqm.TemporalUnit.WEEK_OF_MONTH; import static org.hibernate.query.sqm.TemporalUnit.WEEK_OF_YEAR; +import static org.hibernate.query.sqm.internal.SqmUtil.resolveExpressibleJavaTypeClass; import static org.hibernate.type.descriptor.DateTimeUtils.DATE_TIME; import static org.hibernate.type.spi.TypeConfiguration.isJdbcTemporalType; @@ -2918,8 +2919,11 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem @Override public SqmPredicate visitBooleanExpressionPredicate(HqlParser.BooleanExpressionPredicateContext ctx) { final SqmExpression expression = (SqmExpression) ctx.expression().accept( this ); - if ( expression.getJavaType() != Boolean.class ) { - throw new SemanticException( "Non-boolean expression used in predicate context: " + ctx.getText(), query ); + if ( resolveExpressibleJavaTypeClass( expression ) != Boolean.class ) { + throw new SemanticException( + "Non-boolean expression used in predicate context: " + ctx.getText(), + query + ); } @SuppressWarnings("unchecked") final SqmExpression booleanExpression = (SqmExpression) expression; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java index 0d55513e01..e272212ea1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java @@ -15,6 +15,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.StringTokenizer; import java.util.function.Function; @@ -43,6 +44,7 @@ import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SqmExpressible; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmQuerySource; import org.hibernate.query.sqm.spi.JdbcParameterBySqmParameterAccess; @@ -753,6 +755,13 @@ public class SqmUtil { return selection != null && selection.getSelectableNode() instanceof SqmTuple; } + public static Class resolveExpressibleJavaTypeClass(final SqmExpression expression) { + final SqmExpressible expressible = expression.getExpressible(); + return expressible == null || expressible.getExpressibleJavaType() == null + ? null + : expressible.getExpressibleJavaType().getJavaTypeClass(); + } + private static class CriteriaParameterCollector { private Set> sqmParameters; private Map, List>> jpaCriteriaParamResolutions;