{"record":{"id":"b818c309f3b66b5c","repo":"hibernate/hibernate-orm","slug":"gettypename-as-temporaltype-timestamp-not-su","errorCode":null,"errorMessage":"getTypeName() + \" as TemporalType.TIMESTAMP not supported\"","messagePattern":"getTypeName\\(\\) \\+ \" as TemporalType\\.TIMESTAMP not supported\"","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractTemporalJavaType.java","lineNumber":56,"sourceCode":"\t\t\tTypeConfiguration typeConfiguration) {\n\t\tif ( precision == null ) {\n\t\t\treturn forMissingPrecision( typeConfiguration );\n\t\t}\n\t\telse {\n\t\t\treturn switch ( precision ) {\n\t\t\t\tcase DATE -> forDatePrecision( typeConfiguration );\n\t\t\t\tcase TIME -> forTimePrecision( typeConfiguration );\n\t\t\t\tcase TIMESTAMP -> forTimestampPrecision( typeConfiguration );\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate TemporalJavaType<T> forMissingPrecision(TypeConfiguration typeConfiguration) {\n\t\treturn this;\n\t}\n\n\tprotected TemporalJavaType<T> forTimestampPrecision(TypeConfiguration typeConfiguration) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\tgetTypeName() + \" as TemporalType.TIMESTAMP not supported\"\n\t\t);\n\t}\n\n\tprotected TemporalJavaType<T> forDatePrecision(TypeConfiguration typeConfiguration) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\tgetTypeName() + \" as TemporalType.DATE not supported\"\n\t\t);\n\t}\n\n\tprotected TemporalJavaType<T> forTimePrecision(TypeConfiguration typeConfiguration) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\tgetTypeName() + \" as TemporalType.TIME not supported\"\n\t\t);\n\t}\n\n\t@Override\n\tpublic String toString() {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractTemporalJavaType.java#L38-L74","documentation":"AbstractTemporalJavaType.resolveTypeForPrecision routes a TemporalType.TIMESTAMP request to forTimestampPrecision, which by default throws UnsupportedOperationException. Only descriptors that support timestamp precision (JdbcTimestampJavaType, DateJavaType, CalendarJavaType, OffsetDateTimeJavaType, etc.) override it; a temporal Java type that has no timestamp representation fails here.","triggerScenarios":"Asking Hibernate to treat a temporal type as TIMESTAMP when its descriptor does not support it - e.g. @Temporal(TemporalType.TIMESTAMP) on a java.sql.Time / java.time.LocalTime / java.time.LocalDate field (LocalTimeJavaType and LocalDateJavaType override only their own precision), or programmatic/basic-type requests with timestamp precision.","commonSituations":"Copy-pasted @Temporal annotations mismatched with the field type; migrating fields between java.util.Date (supports all precisions) and java.time types (each supports one precision); legacy mappings using JdbcDate/JdbcTime descriptors with a different @Temporal value; JPA spec note that @Temporal applies to java.util.Date/Calendar only.","solutions":["Align the annotation with the type: LocalDate/@Temporal is invalid - drop @Temporal on java.time fields","Use java.util.Date or java.util.Calendar if one field must work with DATE, TIME and TIMESTAMP precisions","Change the field to a timestamp-capable type (LocalDateTime, OffsetDateTime, Instant, java.util.Date) when TIMESTAMP semantics are needed","Remove programmatic timestamp-precision requests for time-only/date-only types"],"exampleFix":"// before\n@Entity\npublic class Event {\n    @Temporal(TemporalType.TIMESTAMP) // invalid for LocalTime\n    private LocalTime startTime;\n}\n// after\n@Entity\npublic class Event {\n    private LocalTime startTime; // no @Temporal; stored as TIME\n    private LocalDateTime occurredAt; // timestamp semantics\n}","handlingStrategy":"validation","validationCode":"// startup audit: @Temporal only on java.util.Date/Calendar, and precision must fit the type\nfor (Field f : entity.getDeclaredFields()) {\n    Temporal t = f.getAnnotation(Temporal.class);\n    if (t == null) continue;\n    Class<?> ft = f.getType();\n    if (t.value() == TemporalType.TIMESTAMP\n            && !Date.class.isAssignableFrom(ft) && !Calendar.class.isAssignableFrom(ft)\n            && ft != LocalDateTime.class && ft != OffsetDateTime.class && ft != Instant.class) {\n        throw new MappingException(\"TIMESTAMP precision invalid for \" + ft);\n    }\n}","typeGuard":"static boolean supportsTimestampPrecision(Class<?> fieldType) {\n    return Date.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)\n        || fieldType == LocalDateTime.class || fieldType == OffsetDateTime.class\n        || fieldType == Instant.class || fieldType == ZonedDateTime.class\n        || fieldType == java.sql.Timestamp.class;\n}","tryCatchPattern":"try {\n    return session.find(Event.class, id);\n} catch (UnsupportedOperationException e) {\n    if (String.valueOf(e.getMessage()).contains(\"as TemporalType.TIMESTAMP not supported\")) {\n        // mapping bug, not data: fix @Temporal/field type and redeploy - do not retry\n        throw new MappingException(\"Fix temporal mapping on Event.startTime\", e);\n    }\n    throw e;\n}","preventionTips":["Never put @Temporal on java.time fields (JPA forbids it; Hibernate maps them natively)","Use java.util.Date/Calendar when one field must serve multiple precisions","Add a mapping audit test at bootstrap","Review @Temporal usage whenever a field type changes"],"tags":["hibernate","orm","jpa","temporal-type","mapping-exception","date-time"],"backgroundTag":"temporal-precision-not-supported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}