{"record":{"id":"1c9d9a58d8373697","repo":"hibernate/hibernate-orm","slug":"cannot-treat-non-temporal-parameter-type-with-temp","errorCode":null,"errorMessage":"Cannot treat non-temporal parameter type with temporal precision","messagePattern":"Cannot treat non-temporal parameter type with temporal precision","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java","lineNumber":80,"sourceCode":"\t\t\tfinal var descriptor =\n\t\t\t\t\ttypeConfiguration.getJavaTypeRegistry()\n\t\t\t\t\t\t\t.resolveDescriptor( resolveJavaTypeClass( precision ) );\n\t\t\t//noinspection unchecked\n\t\t\treturn (TemporalJavaType<T>) descriptor;\n\t\t}\n\t\telse {\n\t\t\treturn temporalJtd.resolveTypeForPrecision( precision, typeConfiguration );\n\t\t}\n\t}\n\n\tprivate static <T> TemporalJavaType<T> getTemporalJavaType(\n\t\t\tBindableType<T> declaredParameterType, BindingContext bindingContext) {\n\t\tif ( declaredParameterType != null ) {\n\t\t\tfinal var javaType =\n\t\t\t\t\tbindingContext.resolveExpressible( declaredParameterType )\n\t\t\t\t\t\t\t.getExpressibleJavaType();\n\t\t\tif ( !isTemporal( javaType ) ) {\n\t\t\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\t\t\"Cannot treat non-temporal parameter type with temporal precision\"\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn (TemporalJavaType<T>) javaType;\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic static JdbcMapping resolveBindType(JdbcMapping baseType, JdbcParameter jdbcParameter) {\n\t\treturn baseType instanceof NullType && jdbcParameter.getExpressionType() != null\n\t\t\t\t? jdbcParameter.getExpressionType().getSingleJdbcMapping()\n\t\t\t\t: baseType;\n\t}\n\n\tpublic static JdbcMapping resolveBindType(\n\t\t\tObject value,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Bind temporal values without the TemporalType argument - for java.time types Hibernate derives precision from the mapping: setParameter('d', LocalDate.now()).","If you must pass TemporalType, bind a java.util.Date or java.util.Calendar value, which is what the JPA signature allows.","Convert non-temporal inputs before binding, e.g. LocalDate.parse((String) value).","Fix the declared parameter type in the query/stored-procedure registration so it is a temporal class."],"exampleFix":"// before - String value + TemporalType -> UnsupportedOperationException\nquery.setParameter(\"startDate\", \"2024-01-01\", TemporalType.DATE);\n\n// after - temporal value, no explicit precision needed\nquery.setParameter(\"startDate\", java.sql.Date.valueOf(\"2024-01-01\"));\n// or\nquery.setParameter(\"startDate\", LocalDate.parse(\"2024-01-01\"));","handlingStrategy":"type-guard","validationCode":"static boolean isTemporalBind(Object value) {\n    return value instanceof java.util.Date\n        || value instanceof java.util.Calendar\n        || value instanceof java.time.temporal.Temporal;\n}\n\n// guard before binding with a TemporalType\nif ( isTemporalBind( value ) ) {\n    query.setParameter( \"p\", value, TemporalType.DATE );\n} else {\n    query.setParameter( \"p\", value ); // no precision allowed\n}","typeGuard":"static boolean isTemporalType(Class<?> c) {\n    return java.util.Date.class.isAssignableFrom( c )\n        || java.util.Calendar.class.isAssignableFrom( c )\n        || java.time.temporal.Temporal.class.isAssignableFrom( c );\n}","tryCatchPattern":null,"preventionTips":["Never pass a TemporalType argument together with a non-Date/Calendar value.","Drop TemporalType entirely for java.time parameters - the mapping defines precision.","In shared query utilities, branch on the parameter's Java type before choosing the setParameter overload."],"tags":["hibernate","jpa","query-parameters","temporal","date-time"],"backgroundTag":"temporal-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}