From 60a338a044e52eccded73027bb8421b22dcc0136 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 17 Dec 2024 09:57:08 +0100 Subject: [PATCH] HHH-17151 Resolve explicit temporal bind type for null values --- .../query/internal/BindingTypeHelper.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java index c94b9a28e534..4645d81a9f97 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java @@ -39,21 +39,27 @@ public BindableType resolveTemporalPrecision( BindableType declaredParameterType, BindingContext bindingContext) { if ( precision != null ) { - final SqmExpressible sqmExpressible = declaredParameterType.resolveExpressible(bindingContext); - if ( !( JavaTypeHelper.isTemporal( sqmExpressible.getExpressibleJavaType() ) ) ) { - throw new UnsupportedOperationException( - "Cannot treat non-temporal parameter type with temporal precision" - ); + final TemporalJavaType temporalJtd; + if ( declaredParameterType != null ) { + final SqmExpressible sqmExpressible = declaredParameterType.resolveExpressible( bindingContext ); + if ( !( JavaTypeHelper.isTemporal( sqmExpressible.getExpressibleJavaType() ) ) ) { + throw new UnsupportedOperationException( + "Cannot treat non-temporal parameter type with temporal precision" + ); + } + temporalJtd = (TemporalJavaType) sqmExpressible.getExpressibleJavaType(); + } + else { + temporalJtd = null; } - final TemporalJavaType temporalJtd = (TemporalJavaType) sqmExpressible.getExpressibleJavaType(); - if ( temporalJtd.getPrecision() != precision ) { + if ( temporalJtd == null || temporalJtd.getPrecision() != precision ) { final TypeConfiguration typeConfiguration = bindingContext.getTypeConfiguration(); final TemporalJavaType temporalTypeForPrecision; // Special case java.util.Date, because TemporalJavaType#resolveTypeForPrecision doesn't support widening, // since the main purpose of that method is to determine the final java type based on the reflective type // + the explicit @Temporal(TemporalType...) configuration - if ( java.util.Date.class.isAssignableFrom( temporalJtd.getJavaTypeClass() ) ) { + if ( temporalJtd == null || java.util.Date.class.isAssignableFrom( temporalJtd.getJavaTypeClass() ) ) { //noinspection unchecked temporalTypeForPrecision = (TemporalJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( TemporalJavaType.resolveJavaTypeClass( precision )