Skip to content

Commit

Permalink
HHH-17151 Resolve explicit temporal bind type for null values
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Feb 20, 2025
1 parent 7536494 commit 60a338a
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,27 @@ public <T> BindableType<T> resolveTemporalPrecision(
BindableType<T> declaredParameterType,
BindingContext bindingContext) {
if ( precision != null ) {
final SqmExpressible<T> sqmExpressible = declaredParameterType.resolveExpressible(bindingContext);
if ( !( JavaTypeHelper.isTemporal( sqmExpressible.getExpressibleJavaType() ) ) ) {
throw new UnsupportedOperationException(
"Cannot treat non-temporal parameter type with temporal precision"
);
final TemporalJavaType<T> temporalJtd;
if ( declaredParameterType != null ) {
final SqmExpressible<T> sqmExpressible = declaredParameterType.resolveExpressible( bindingContext );
if ( !( JavaTypeHelper.isTemporal( sqmExpressible.getExpressibleJavaType() ) ) ) {
throw new UnsupportedOperationException(
"Cannot treat non-temporal parameter type with temporal precision"
);
}
temporalJtd = (TemporalJavaType<T>) sqmExpressible.getExpressibleJavaType();
}
else {
temporalJtd = null;
}

final TemporalJavaType<T> temporalJtd = (TemporalJavaType<T>) sqmExpressible.getExpressibleJavaType();
if ( temporalJtd.getPrecision() != precision ) {
if ( temporalJtd == null || temporalJtd.getPrecision() != precision ) {
final TypeConfiguration typeConfiguration = bindingContext.getTypeConfiguration();
final TemporalJavaType<T> 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<T>) typeConfiguration.getJavaTypeRegistry().getDescriptor(
TemporalJavaType.resolveJavaTypeClass( precision )
Expand Down

0 comments on commit 60a338a

Please sign in to comment.