{"record":{"id":"4e0127e6dac3817a","repo":"hibernate/hibernate-orm","slug":"unsure-how-to-handle-given-java-type-as-tempo","errorCode":null,"errorMessage":"Unsure how to handle given Java type [{}] as TemporalType#TIMESTAMP","messagePattern":"Unsure how to handle given Java type \\[(.+?)\\] as TemporalType#TIMESTAMP","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java","lineNumber":143,"sourceCode":"\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.CALENDAR );\n\t\t}\n\t\telse if ( java.util.Date.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.TIMESTAMP );\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 if ( OffsetTime.class.isAssignableFrom( javaType ) ) {\n\t\t\treturn typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.OFFSET_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#TIMESTAMP\" );\n\t\t}\n\t}\n\n\tprivate static BindableType<?> resolveDateTemporalTypeVariant(\n\t\t\tClass<?> javaType,\n\t\t\tBindableType<?> baseType,\n\t\t\tTypeConfiguration typeConfiguration) {\n\t\tif ( baseType.getJavaType().isAssignableFrom( javaType ) ) {\n\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 ) ) {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/internal/BindingTypeHelper.java#L125-L161","documentation":"When a parameter is bound with TemporalType.TIMESTAMP, BindingTypeHelper.resolveTimestampTemporalTypeVariant maps the parameter's Java type to a TIMESTAMP-capable basic type (BindingTypeHelper.java:123-146). It handles java.util.Date, Calendar, LocalDateTime, Instant, OffsetDateTime, ZonedDateTime and OffsetTime; any other class falls through to this IllegalArgumentException naming the unsupported Java type.","triggerScenarios":"Query.setParameter('ts', LocalDate.now(), TemporalType.TIMESTAMP) - LocalDate has no TIMESTAMP variant; passing LocalTime, YearMonth, java.sql.Date subclasses outside the handled set, or a custom temporal-ish class with TemporalType.TIMESTAMP; stored-procedure parameters bound the same way.","commonSituations":"Migrating fields from java.util.Date to java.time types while keeping old TemporalType.TIMESTAMP arguments; code written for one temporal family (LocalDate) reused with precision meant for another (TIMESTAMP).","solutions":["Drop the TemporalType argument entirely - Hibernate already maps LocalDate/LocalTime/LocalDateTime correctly without it.","Use TemporalType.DATE for LocalDate, TemporalType.TIME for LocalTime, and reserve TemporalType.TIMESTAMP for LocalDateTime/Instant/OffsetDateTime/ZonedDateTime/Date/Calendar.","Convert the value: value.atStartOfDay() for LocalDate, value.atDate(...) for LocalTime, before binding with TIMESTAMP precision."],"exampleFix":"// before - LocalDate cannot be bound as TIMESTAMP\nquery.setParameter(\"ts\", LocalDate.now(), TemporalType.TIMESTAMP);\n\n// after - either let Hibernate infer\nquery.setParameter(\"ts\", LocalDate.now());\n// or convert to a TIMESTAMP-capable type\nquery.setParameter(\"ts\", LocalDate.now().atStartOfDay());","handlingStrategy":"type-guard","validationCode":"static final Set<Class<?>> TIMESTAMP_OK = Set.of(\n    java.util.Date.class, java.util.Calendar.class,\n    java.time.LocalDateTime.class, java.time.Instant.class,\n    java.time.OffsetDateTime.class, java.time.ZonedDateTime.class,\n    java.time.OffsetTime.class );\n\nif ( !TIMESTAMP_OK.contains( value.getClass() ) ) {\n    throw new IllegalArgumentException( \"Bind \" + value.getClass().getSimpleName()\n        + \" without TemporalType, or convert to a timestamp-capable type\" );\n}","typeGuard":"static boolean supportsTimestampPrecision(Object v) {\n    return v instanceof java.util.Date || v instanceof java.util.Calendar\n        || v instanceof java.time.LocalDateTime || v instanceof java.time.Instant\n        || v instanceof java.time.OffsetDateTime || v instanceof java.time.ZonedDateTime\n        || v instanceof java.time.OffsetTime;\n}","tryCatchPattern":null,"preventionTips":["Map TemporalType.DATE->LocalDate, TIME->LocalTime/OffsetTime, TIMESTAMP->LocalDateTime/Instant/OffsetDateTime/ZonedDateTime/Date/Calendar.","Prefer omitting the TemporalType argument for java.time types.","Centralize temporal binding in one helper that applies the compatibility table."],"tags":["hibernate","jpa","query-parameters","temporal","timestamp"],"backgroundTag":"temporal-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}