@@ -41,18 +41,40 @@ public <T> BindableType<T> resolveTemporalPrecision(
4141 BindableType <T > declaredParameterType ,
4242 SessionFactoryImplementor sessionFactory ) {
4343 if ( precision != null ) {
44- final SqmExpressible <T > sqmExpressible = declaredParameterType .resolveExpressible ( sessionFactory );
45- if ( !( JavaTypeHelper .isTemporal ( sqmExpressible .getExpressibleJavaType () ) ) ) {
46- throw new UnsupportedOperationException (
47- "Cannot treat non-temporal parameter type with temporal precision"
48- );
44+ final TemporalJavaType <T > temporalJtd ;
45+ if ( declaredParameterType != null ) {
46+ final SqmExpressible <T > sqmExpressible = declaredParameterType .resolveExpressible ( sessionFactory );
47+ if ( !( JavaTypeHelper .isTemporal ( sqmExpressible .getExpressibleJavaType () ) ) ) {
48+ throw new UnsupportedOperationException (
49+ "Cannot treat non-temporal parameter type with temporal precision"
50+ );
51+ }
52+ temporalJtd = (TemporalJavaType <T >) sqmExpressible .getExpressibleJavaType ();
53+ }
54+ else {
55+ temporalJtd = null ;
4956 }
5057
51- final TemporalJavaType <T > temporalJtd = (TemporalJavaType <T >) sqmExpressible .getExpressibleJavaType ();
52- if ( temporalJtd .getPrecision () != precision ) {
58+ if ( temporalJtd == null || temporalJtd .getPrecision () != precision ) {
5359 final TypeConfiguration typeConfiguration = sessionFactory .getTypeConfiguration ();
60+ final TemporalJavaType <T > temporalTypeForPrecision ;
61+ // Special case java.util.Date, because TemporalJavaType#resolveTypeForPrecision doesn't support widening,
62+ // since the main purpose of that method is to determine the final java type based on the reflective type
63+ // + the explicit @Temporal(TemporalType...) configuration
64+ if ( temporalJtd == null || java .util .Date .class .isAssignableFrom ( temporalJtd .getJavaTypeClass () ) ) {
65+ //noinspection unchecked
66+ temporalTypeForPrecision = (TemporalJavaType <T >) typeConfiguration .getJavaTypeRegistry ().getDescriptor (
67+ TemporalJavaType .resolveJavaTypeClass ( precision )
68+ );
69+ }
70+ else {
71+ temporalTypeForPrecision = temporalJtd .resolveTypeForPrecision (
72+ precision ,
73+ typeConfiguration
74+ );
75+ }
5476 return typeConfiguration .getBasicTypeRegistry ().resolve (
55- temporalJtd . resolveTypeForPrecision ( precision , typeConfiguration ) ,
77+ temporalTypeForPrecision ,
5678 TemporalJavaType .resolveJdbcTypeCode ( precision )
5779 );
5880 }
0 commit comments