Skip to content

Commit a3f891e

Browse files
committed
HHH-19085 NPE when using null value in CriteriaUpdate
1 parent 933c1d2 commit a3f891e

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
@@ -8,6 +8,7 @@
88
import org.hibernate.HibernateException;
99
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1010
import org.hibernate.graph.spi.AppliedGraph;
11+
import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter;
1112
import org.hibernate.type.BindableType;
1213
import org.hibernate.query.IllegalSelectQueryException;
1314
import org.hibernate.query.KeyedPage;
@@ -158,14 +159,11 @@ else if ( bindType != null ) {
158159

159160
protected <T> void bindCriteriaParameter(SqmJpaCriteriaParameterWrapper<T> sqmParameter) {
160161
final JpaCriteriaParameter<T> criteriaParameter = sqmParameter.getJpaCriteriaParameter();
161-
final T value = criteriaParameter.getValue();
162-
// We don't set a null value, unless the type is also null which
163-
// is the case when using HibernateCriteriaBuilder.value
164-
if ( value != null || criteriaParameter.getNodeType() == null ) {
162+
if ( criteriaParameter instanceof ValueBindJpaCriteriaParameter<?> ) {
165163
// Use the anticipated type for binding the value if possible
166164
getQueryParameterBindings()
167165
.getBinding( criteriaParameter )
168-
.setBindValue( value, criteriaParameter.getAnticipatedType() );
166+
.setBindValue( criteriaParameter.getValue(), criteriaParameter.getAnticipatedType() );
169167
}
170168
}
171169

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
@@ -2147,7 +2147,10 @@ else if ( value instanceof SqmExpression<?> ) {
21472147
}
21482148

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

0 commit comments

Comments
 (0)