20
20
import org .hibernate .query .spi .QueryParameterBinding ;
21
21
import org .hibernate .query .spi .QueryParameterBindingValidator ;
22
22
import org .hibernate .query .sqm .SqmExpressible ;
23
+ import org .hibernate .query .sqm .tree .expression .NullSqmExpressible ;
23
24
import org .hibernate .type .descriptor .java .JavaType ;
24
25
import org .hibernate .type .descriptor .java .JavaTypeHelper ;
25
26
import org .hibernate .type .spi .TypeConfiguration ;
@@ -113,10 +114,10 @@ public void setBindValue(T value, boolean resolveJdbcTypeIfNecessary) {
113
114
final Object coerced ;
114
115
if ( ! sessionFactory .getSessionFactoryOptions ().getJpaCompliance ().isLoadByIdComplianceEnabled () ) {
115
116
try {
116
- if ( bindType != null ) {
117
+ if ( canValueBeCoerced ( bindType ) ) {
117
118
coerced = coerce ( value , bindType );
118
119
}
119
- else if ( queryParameter .getHibernateType () != null ) {
120
+ else if ( canValueBeCoerced ( queryParameter .getHibernateType () ) ) {
120
121
coerced = coerce ( value , queryParameter .getHibernateType () );
121
122
}
122
123
else {
@@ -190,7 +191,7 @@ private boolean isRegisteredAsBasicType(Class<?> valueClass) {
190
191
private void bindValue (Object value ) {
191
192
isBound = true ;
192
193
bindValue = value ;
193
- if ( bindType == null && value != null ) {
194
+ if ( canBindValueBeSet ( value , bindType ) ) {
194
195
bindType = sessionFactory .getMappingMetamodel ().resolveParameterBindType ( value );
195
196
}
196
197
}
@@ -206,10 +207,10 @@ public void setBindValue(T value, BindableType<T> clarifiedType) {
206
207
}
207
208
208
209
final Object coerced ;
209
- if ( bindType != null ) {
210
+ if ( canValueBeCoerced ( bindType ) ) {
210
211
coerced = coerce ( value , bindType );
211
212
}
212
- else if ( queryParameter .getHibernateType () != null ) {
213
+ else if ( canValueBeCoerced ( queryParameter .getHibernateType () ) ) {
213
214
coerced = coerce ( value , queryParameter .getHibernateType () );
214
215
}
215
216
else {
@@ -233,7 +234,7 @@ public void setBindValue(T value, TemporalType temporalTypePrecision) {
233
234
234
235
final Object coerced ;
235
236
if ( ! sessionFactory .getSessionFactoryOptions ().getJpaCompliance ().isLoadByIdComplianceEnabled () ) {
236
- if ( bindType != null ) {
237
+ if (canValueBeCoerced ( bindType ) ) {
237
238
try {
238
239
coerced = coerce ( value , bindType );
239
240
}
@@ -249,7 +250,7 @@ public void setBindValue(T value, TemporalType temporalTypePrecision) {
249
250
);
250
251
}
251
252
}
252
- else if ( queryParameter .getHibernateType () != null ) {
253
+ else if ( canValueBeCoerced ( queryParameter .getHibernateType () ) ) {
253
254
coerced = coerce ( value , queryParameter .getHibernateType () );
254
255
}
255
256
else {
@@ -299,10 +300,9 @@ public void setBindValues(Collection<? extends T> values) {
299
300
value = iterator .next ();
300
301
}
301
302
302
- if ( bindType == null && value != null ) {
303
- this . bindType = sessionFactory .getMappingMetamodel ().resolveParameterBindType ( value );
303
+ if ( canBindValueBeSet ( value , bindType ) ) {
304
+ bindType = sessionFactory .getMappingMetamodel ().resolveParameterBindType ( value );
304
305
}
305
-
306
306
}
307
307
308
308
@ Override
@@ -378,4 +378,12 @@ private void validate(Object value, TemporalType clarifiedTemporalType) {
378
378
public TypeConfiguration getTypeConfiguration () {
379
379
return sessionFactory .getTypeConfiguration ();
380
380
}
381
+
382
+ private static boolean canValueBeCoerced (BindableType <?> bindType ) {
383
+ return bindType != null && !( bindType instanceof NullSqmExpressible );
384
+ }
385
+
386
+ private static boolean canBindValueBeSet (Object value , BindableType <?> bindType ) {
387
+ return value != null && ( bindType == null || bindType instanceof NullSqmExpressible );
388
+ }
381
389
}
0 commit comments