{"record":{"id":"1f777794820806b6","repo":"hibernate/hibernate-orm","slug":"unsure-how-to-handle-given-java-type-as-tempo-1f7777","errorCode":null,"errorMessage":"Unsure how to handle given Java type [{}] as TemporalType#DATE","messagePattern":"Unsure how to handle given Java type \\[(.+?)\\] as TemporalType#DATE","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java","lineNumber":171,"sourceCode":"\t\t\treturn baseType;\n\t\t}\n\t\telse if ( Calendar.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.CALENDAR_DATE );\n\t\t}\n\t\telse if ( java.util.Date.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.DATE );\n\t\t}\n\t\telse if ( Instant.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.INSTANT );\n\t\t}\n\t\telse if ( OffsetDateTime.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.OFFSET_DATE_TIME );\n\t\t}\n\t\telse if ( ZonedDateTime.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.ZONED_DATE_TIME );\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException( \"Unsure how to handle given Java type [\"\n\t\t\t\t\t\t\t\t\t\t\t\t+ javaType.getName() + \"] as TemporalType#DATE\" );\n\t\t}\n\t}\n\n\tprivate static BindableType<?> resolveTimeTemporalTypeVariant(\n\t\t\tClass<?> javaType,\n\t\t\tBindableType<?> baseType,\n\t\t\tTypeConfiguration typeConfiguration) {\n\t\tif ( Calendar.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.CALENDAR_TIME );\n\t\t}\n\t\telse if ( java.util.Date.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.TIME );\n\t\t}\n\t\telse if ( LocalTime.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.LOCAL_TIME );\n\t\t}\n\t\telse if ( OffsetTime.class.isAssignableFrom( javaType ) ) {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java#L153-L189","documentation":"When a parameter is bound with TemporalType.DATE, BindingTypeHelper.resolveDateTemporalTypeVariant maps the parameter's Java type to a DATE basic type (BindingTypeHelper.java:151-174). It accepts the assignable base type, Calendar, java.util.Date, LocalDate, Instant, OffsetDateTime and ZonedDateTime; any other class falls through to this IllegalArgumentException naming the unsupported Java type.","triggerScenarios":"Query.setParameter('d', LocalTime.now(), TemporalType.DATE) or LocalDateTime with DATE precision - neither is a DATE-only type in the handled set; binding custom date-like classes with TemporalType.DATE.","commonSituations":"Reusing a TemporalType.DATE argument on time-carrying types after a field changed from Date to LocalTime/LocalDateTime; copy-pasted stored-procedure binding code applied to parameters of the wrong temporal kind.","solutions":["Remove the TemporalType argument and let Hibernate derive precision from the mapped attribute/parameter type.","Use TemporalType.TIME for LocalTime/OffsetTime and TemporalType.TIMESTAMP for LocalDateTime, or convert the value to LocalDate before binding with DATE precision.","For custom temporal classes, bind a standard type (LocalDate) converted from your class."],"exampleFix":"// before - LocalTime cannot be bound as DATE\nquery.setParameter(\"d\", LocalTime.now(), TemporalType.DATE);\n\n// after - correct precision for the type\nquery.setParameter(\"t\", LocalTime.now(), TemporalType.TIME);\n// or simply\nquery.setParameter(\"t\", LocalTime.now());","handlingStrategy":"type-guard","validationCode":"static final Set<Class<?>> DATE_OK = Set.of(\n    java.util.Date.class, java.util.Calendar.class, java.time.LocalDate.class,\n    java.time.Instant.class, java.time.OffsetDateTime.class, java.time.ZonedDateTime.class );\n\nif ( !DATE_OK.contains( value.getClass() ) ) {\n    throw new IllegalArgumentException( \"Type \" + value.getClass().getSimpleName()\n        + \" cannot be bound with TemporalType.DATE\" );\n}","typeGuard":"static boolean supportsDatePrecision(Object v) {\n    return v instanceof java.util.Date || v instanceof java.util.Calendar\n        || v instanceof java.time.LocalDate || v instanceof java.time.Instant\n        || v instanceof java.time.OffsetDateTime || v instanceof java.time.ZonedDateTime;\n}","tryCatchPattern":null,"preventionTips":["Do not reuse TemporalType.DATE for LocalTime/LocalDateTime parameters.","When converting fields from Date to java.time types, audit every setParameter call with a TemporalType argument.","Write a unit test matrix of (value type x TemporalType) against your binding helper."],"tags":["hibernate","jpa","query-parameters","temporal","date"],"backgroundTag":"temporal-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}