{"record":{"id":"41762a485536b0dd","repo":"hibernate/hibernate-orm","slug":"gettypename-as-temporaltype-date-not-support","errorCode":null,"errorMessage":"getTypeName() + \" as TemporalType.DATE not supported\"","messagePattern":"getTypeName\\(\\) \\+ \" as TemporalType\\.DATE not supported\"","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractTemporalJavaType.java","lineNumber":62,"sourceCode":"\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() {\n\t\treturn \"TemporalJavaType(javaType=\" + getTypeName() + \")\";\n\t}\n}\n","sourceCodeStart":44,"sourceCodeEnd":78,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractTemporalJavaType.java#L44-L78","documentation":"The DATE-precision counterpart of the temporal precision checks: AbstractTemporalJavaType.resolveTypeForPrecision(TemporalType.DATE, ...) falls through to forDatePrecision, whose default implementation throws UnsupportedOperationException. Types with no date-only representation (e.g. LocalTime, OffsetTime, JdbcTimeJavaType) fail with this message.","triggerScenarios":"@Temporal(TemporalType.DATE) (or an equivalent precision request) on a time-only field such as java.sql.Time / LocalTime / OffsetTime; also java.time.OffsetDateTime/LocalDateTime descriptors do not override forDatePrecision, so requests to narrow them to DATE throw.","commonSituations":"Annotating every date-ish field with the same @Temporal value by mistake; switching a field from java.util.Date (all precisions) to LocalTime but keeping @Temporal(DATE); tools/DDL validators that request DATE precision for time columns.","solutions":["Remove or fix @Temporal on java.time fields (spec only defines it for java.util.Date/Calendar)","Use a date-capable type (LocalDate, java.util.Date, Calendar) when DATE precision is required","For a java.util.Date field storing date-only values, keep @Temporal(DATE) - DateJavaType supports all three precisions","Audit mappings for copy-pasted @Temporal annotations"],"exampleFix":"// before\n@Entity\npublic class Shift {\n    @Temporal(TemporalType.DATE) // LocalTime has no date precision\n    private LocalTime start;\n}\n// after\n@Entity\npublic class Shift {\n    private LocalTime start; // TIME by default\n}","handlingStrategy":"validation","validationCode":"for (Field f : entity.getDeclaredFields()) {\n    Temporal t = f.getAnnotation(Temporal.class);\n    if (t != null && t.value() == TemporalType.DATE && isTimeOnlyType(f.getType())) {\n        throw new MappingException(\"DATE precision invalid for \" + f);\n    }\n}","typeGuard":"static boolean supportsDatePrecision(Class<?> fieldType) {\n    return Date.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)\n        || fieldType == LocalDate.class || fieldType == java.sql.Date.class;\n}","tryCatchPattern":"try {\n    session.persist(event);\n} catch (UnsupportedOperationException e) {\n    if (String.valueOf(e.getMessage()).contains(\"as TemporalType.DATE not supported\")) {\n        throw new MappingException(\"Fix @Temporal(DATE) on time-only field\", e); // fix mapping, no retry\n    }\n    throw e;\n}","preventionTips":["Map date-only data as LocalDate without @Temporal","Keep @Temporal exclusively on java.util.Date/Calendar fields","Grep for @Temporal after changing any temporal field type","Cover each temporal mapping with a persist+load round-trip test"],"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"}