Skip to content

Commit b213acb

Browse files
committed
HHH-19085 NPE when using null value in CriteriaUpdate
1 parent 65c15d8 commit b213acb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AbstractSqmSelectionQuery.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1010
import org.hibernate.query.spi.QueryParameterImplementor;
1111
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
12+
import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter;
1213
import org.hibernate.type.BindableType;
1314
import org.hibernate.query.KeyedPage;
1415
import org.hibernate.query.KeyedResultList;
@@ -149,15 +150,12 @@ protected static void bindValueBindCriteriaParameters(
149150
if ( sqmParameter instanceof SqmJpaCriteriaParameterWrapper<?> wrapper ) {
150151
@SuppressWarnings("unchecked")
151152
final var criteriaParameter = (JpaCriteriaParameter<Object>) wrapper.getJpaCriteriaParameter();
152-
final var value = criteriaParameter.getValue();
153-
// We don't set a null value, unless the type is also null which
154-
// is the case when using HibernateCriteriaBuilder.value
155-
if ( value != null || criteriaParameter.getNodeType() == null ) {
153+
if ( criteriaParameter instanceof ValueBindJpaCriteriaParameter<?> ) {
156154
// Use the anticipated type for binding the value if possible
157155
//noinspection unchecked
158156
final var parameter = (QueryParameterImplementor<Object>) entry.getKey();
159157
bindings.getBinding( parameter )
160-
.setBindValue( value, criteriaParameter.getAnticipatedType() );
158+
.setBindValue( criteriaParameter.getValue(), criteriaParameter.getAnticipatedType() );
161159
}
162160
}
163161
}

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,10 @@ else if ( value instanceof SqmExpression<?> ) {
21462146
}
21472147

21482148
private <T> boolean isInstance(BindableType<? extends T> bindableType, T value) {
2149-
if ( bindableType instanceof SqmExpressible<?> expressible ) {
2149+
if ( value == null ) {
2150+
return true;
2151+
}
2152+
else if ( bindableType instanceof SqmExpressible<?> expressible ) {
21502153
return expressible.getExpressibleJavaType().isInstance( value );
21512154
}
21522155
else {

0 commit comments

Comments
 (0)