hibernate/hibernate-orm · error · UnsupportedOperationException

Cannot treat non-temporal parameter type with temporal preci

Error message

Cannot treat non-temporal parameter type with temporal precision

What it means

BindingTypeHelper.resolveTemporalPrecision resolves the effective bind type when a parameter is bound with a jakarta.persistence.TemporalType precision. getTemporalJavaType (BindingTypeHelper.java:73-90) resolves the declared parameter type and throws this UnsupportedOperationException as soon as its JavaType is not temporal - the API contract (java.util.Date/Calendar or java.time temporal types) was violated before any type resolution could happen.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java:80

			final var descriptor =
					typeConfiguration.getJavaTypeRegistry()
							.resolveDescriptor( resolveJavaTypeClass( precision ) );
			//noinspection unchecked
			return (TemporalJavaType<T>) descriptor;
		}
		else {
			return temporalJtd.resolveTypeForPrecision( precision, typeConfiguration );
		}
	}

	private static <T> TemporalJavaType<T> getTemporalJavaType(
			BindableType<T> declaredParameterType, BindingContext bindingContext) {
		if ( declaredParameterType != null ) {
			final var javaType =
					bindingContext.resolveExpressible( declaredParameterType )
							.getExpressibleJavaType();
			if ( !isTemporal( javaType ) ) {
				throw new UnsupportedOperationException(
						"Cannot treat non-temporal parameter type with temporal precision"
				);
			}
			return (TemporalJavaType<T>) javaType;
		}
		else {
			return null;
		}
	}

	public static JdbcMapping resolveBindType(JdbcMapping baseType, JdbcParameter jdbcParameter) {
		return baseType instanceof NullType && jdbcParameter.getExpressionType() != null
				? jdbcParameter.getExpressionType().getSingleJdbcMapping()
				: baseType;
	}

	public static JdbcMapping resolveBindType(
			Object value,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Bind temporal values without the TemporalType argument - for java.time types Hibernate derives precision from the mapping: setParameter('d', LocalDate.now()).
  2. If you must pass TemporalType, bind a java.util.Date or java.util.Calendar value, which is what the JPA signature allows.
  3. Convert non-temporal inputs before binding, e.g. LocalDate.parse((String) value).
  4. Fix the declared parameter type in the query/stored-procedure registration so it is a temporal class.

Example fix

// before - String value + TemporalType -> UnsupportedOperationException
query.setParameter("startDate", "2024-01-01", TemporalType.DATE);

// after - temporal value, no explicit precision needed
query.setParameter("startDate", java.sql.Date.valueOf("2024-01-01"));
// or
query.setParameter("startDate", LocalDate.parse("2024-01-01"));
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean isTemporalBind(Object value) {
    return value instanceof java.util.Date
        || value instanceof java.util.Calendar
        || value instanceof java.time.temporal.Temporal;
}

// guard before binding with a TemporalType
if ( isTemporalBind( value ) ) {
    query.setParameter( "p", value, TemporalType.DATE );
} else {
    query.setParameter( "p", value ); // no precision allowed
}

Type guard

static boolean isTemporalType(Class<?> c) {
    return java.util.Date.class.isAssignableFrom( c )
        || java.util.Calendar.class.isAssignableFrom( c )
        || java.time.temporal.Temporal.class.isAssignableFrom( c );
}

Prevention

When it happens

Trigger: Calling Query.setParameter(name, value, TemporalType.DATE/TIME/TIMESTAMP) where value/declared parameter type is non-temporal (String, Integer, custom type); StoredProcedureQuery parameters registered with a non-temporal Java class and bound with a TemporalType; binding a null with an explicitly declared non-temporal parameter type plus temporal precision.

Common situations: Copy-pasted setParameter(.., TemporalType.DATE) calls left on parameters whose Java type changed to String or an enum; passing a formatted date string where a Date/LocalDate is expected; migration to java.time types without removing now-redundant TemporalType arguments.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/1c9d9a58d8373697. Report an issue: GitHub.