{"record":{"id":"8e0c2a6651e43372","repo":"hibernate/hibernate-orm","slug":"could-not-parse-time-string-s","errorCode":null,"errorMessage":"could not parse time string %s","messagePattern":"could not parse time string (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java","lineNumber":271,"sourceCode":"\t@Override\n\tpublic Date fromString(CharSequence string) {\n\t\ttry {\n\t\t\tfinal var temporalAccessor = LITERAL_FORMATTER.parse( string );\n\t\t\treturn java.sql.Date.valueOf( temporalAccessor.query( LocalDate::from ) );\n\t\t}\n\t\tcatch ( DateTimeParseException pe) {\n\t\t\tthrow new HibernateException( \"could not parse date string \" + string, pe );\n\t\t}\n\t}\n\n\t@Override\n\tpublic Date fromEncodedString(CharSequence charSequence, int start, int end) {\n\t\ttry {\n\t\t\tfinal var temporalAccessor = ENCODED_FORMATTER.parse( subSequence( charSequence, start, end ) );\n\t\t\treturn java.sql.Date.valueOf( temporalAccessor.query( LocalDate::from ) );\n\t\t}\n\t\tcatch ( DateTimeParseException pe) {\n\t\t\tthrow new HibernateException( \"could not parse time string \" + subSequence( charSequence, start, end ), pe );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void appendEncodedString(SqlAppender sb, Date value) {\n\t\tLITERAL_FORMATTER.formatTo( fromDate( value ), sb );\n\t}\n\n\t@Override\n\tpublic JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {\n\t\treturn context.getJdbcType( Types.DATE );\n\t}\n\n\t@Override\n\tprotected TemporalJavaType<Date> forDatePrecision(TypeConfiguration typeConfiguration) {\n\t\treturn this;\n\t}\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java#L253-L289","documentation":"fromEncodedString() rehydrates java.sql.Date values that Hibernate stored as encoded text (used on databases without a native DATE type, where the value lives in a VARCHAR column). It parses with a formatter built from ISO_DATE plus an optional 'T'+ISO_LOCAL_TIME tail. When the stored text is not ISO-8601 date, the DateTimeParseException is wrapped in HibernateException. Note the message text says \"could not parse time string\" although this is the date descriptor - a copy-paste artifact in the message, not an indication that a time was requested.","triggerScenarios":"A DATE column materialized as text containing '2024/12/31', '31-DEC-24', an empty string, or text with a space separator; running on a dialect that encodes dates as strings after the data was written by a different tool/version in another format; reading rows restored from a dump that reformatted dates.","commonSituations":"Database migrations between dialects with different textual date encodings; legacy varchar columns holding dates now mapped as Date; data written by an older Hibernate version or an external ETL job.","solutions":["Inspect the actual column content and normalize it to ISO date text (yyyy-MM-dd, optionally yyyy-MM-ddTHH:mm:ss)","If the database has a native DATE type, alter the column so Hibernate never uses the encoded-string path","Add an AttributeConverter that parses the legacy format into java.sql.Date for that entity field","Reject or clean empty strings and whitespace-padded values in the data"],"exampleFix":"// before (varchar column contains '31-DEC-24')\n// read of entity triggers HibernateException: could not parse time string 31-DEC-24\n\n// after\nUPDATE events SET day_text = TO_CHAR(TO_DATE(day_text,'DD-MON-RR'),'YYYY-MM-DD');\n-- or map the column with an AttributeConverter parsing 'DD-MON-RR'","handlingStrategy":"validation","validationCode":"static boolean parsesAsEncodedDate(CharSequence s) {\n    try {\n        java.time.format.DateTimeFormatter f = java.time.format.DateTimeFormatter.ISO_DATE;\n        f.parse(s); return true;\n    } catch (java.time.format.DateTimeParseException e) { return false; }\n}\n\n// guard reads of text columns backing Date attributes:\nif (!parsesAsEncodedDate(row.get(\"day\"))) logAndQuarantine(row);","typeGuard":null,"tryCatchPattern":"try { entity.setDay(row.getDate(\"day\")); }\ncatch (HibernateException e) {\n    if (e.getCause() instanceof DateTimeParseException) { /* flag row for data repair, skip */ }\n    else throw e;\n}","preventionTips":["Prefer native DATE columns over varchar-encoded dates","Run a data-quality pass (parse-check every value) after imports","Keep write and read paths on the same dialect/encoder; re-verify data after migrations"],"tags":["hibernate","date-parsing","encoded-string","varchar-date","dialect","misleading-message"],"backgroundTag":"datetime-string-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}