diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AbstractSqmSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AbstractSqmSelectionQuery.java index 4765de3d31..64c02a4a6e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AbstractSqmSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AbstractSqmSelectionQuery.java @@ -155,6 +155,7 @@ abstract class AbstractSqmSelectionQuery extends AbstractSelectionQuery { private void addRestrictions(List> keyDefinition, List> keyValues) { SqmSelectStatement sqm = getSqmSelectStatement(); sqm = sqm.copy( noParamCopyContext() ); + final NodeBuilder builder = sqm.nodeBuilder(); final SqmQuerySpec querySpec = sqm.getQuerySpec(); final SqmWhereClause whereClause = querySpec.getWhereClause(); final List> items = querySpec.getSelectClause().getSelectionItems(); @@ -166,7 +167,8 @@ abstract class AbstractSqmSelectionQuery extends AbstractSelectionQuery { whereClause.applyPredicate( keyPredicate( (SqmFrom) selected, keyDefinition.get(i), - (Comparable) keyValues.get(i)) + (Comparable) keyValues.get(i), + builder) ); } else { @@ -184,17 +186,21 @@ abstract class AbstractSqmSelectionQuery extends AbstractSelectionQuery { } private > SqmPredicate keyPredicate( - SqmFrom selected, Order key, C keyValue) { + SqmFrom selected, Order key, C keyValue, NodeBuilder builder) { if ( !key.getEntityClass().isAssignableFrom( selected.getJavaType() ) ) { throw new IllegalQueryOperationException("Select item was of wrong entity type"); } final Expression path = selected.get( key.getAttributeName() ); - final NodeBuilder builder = getSqmStatement().nodeBuilder(); + // TODO: use a parameter here and create a binding for it +// @SuppressWarnings("unchecked") +// final Class valueClass = (Class) keyValue.getClass(); +// final JpaParameterExpression parameter = builder.parameter(valueClass); +// setParameter( parameter, keyValue ); switch ( key.getDirection() ) { case ASCENDING: - return builder.greaterThan( path, keyValue); + return builder.greaterThan( path, builder.literal(keyValue) ); case DESCENDING: - return builder.lessThan( path, keyValue); + return builder.lessThan( path, builder.literal(keyValue) ); default: throw new AssertionFailure("Unrecognized key direction"); }