@@ -41,18 +41,40 @@ public <T> BindableType<T> resolveTemporalPrecision(
41
41
BindableType <T > declaredParameterType ,
42
42
SessionFactoryImplementor sessionFactory ) {
43
43
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 ;
49
56
}
50
57
51
- final TemporalJavaType <T > temporalJtd = (TemporalJavaType <T >) sqmExpressible .getExpressibleJavaType ();
52
- if ( temporalJtd .getPrecision () != precision ) {
58
+ if ( temporalJtd == null || temporalJtd .getPrecision () != precision ) {
53
59
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
+ }
54
76
return typeConfiguration .getBasicTypeRegistry ().resolve (
55
- temporalJtd . resolveTypeForPrecision ( precision , typeConfiguration ) ,
77
+ temporalTypeForPrecision ,
56
78
TemporalJavaType .resolveJdbcTypeCode ( precision )
57
79
);
58
80
}
0 commit comments