{"record":{"id":"d8d986d8bfa3428f","repo":"hibernate/hibernate-orm","slug":"could-not-parse-timestamp-string-s","errorCode":null,"errorMessage":"could not parse timestamp string %s","messagePattern":"could not parse timestamp string (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java","lineNumber":227,"sourceCode":"\t\t\tdefault -> false;\n\t\t};\n\t}\n\n\t@Override\n\tpublic String toString(Timestamp value) {\n\t\treturn LITERAL_FORMATTER.format( value.toInstant() );\n\t}\n\n\t@Override\n\tpublic Timestamp fromString(CharSequence string) {\n\t\ttry {\n\t\t\tfinal var temporalAccessor = LITERAL_FORMATTER.parse( string );\n\t\t\tfinal var timestamp = new Timestamp( temporalAccessor.getLong( ChronoField.INSTANT_SECONDS ) * 1000L );\n\t\t\ttimestamp.setNanos( temporalAccessor.get( ChronoField.NANO_OF_SECOND ) );\n\t\t\treturn timestamp;\n\t\t}\n\t\tcatch ( DateTimeParseException pe) {\n\t\t\tthrow new HibernateException( \"could not parse timestamp string \" + string, pe );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void appendEncodedString(SqlAppender sb, Timestamp value) {\n\t\tENCODED_FORMATTER.formatTo( value.toInstant(), sb );\n\t}\n\n\t@Override\n\tpublic Timestamp 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\tif ( temporalAccessor.isSupported( ChronoField.INSTANT_SECONDS ) ) {\n\t\t\t\tfinal var timestamp = new Timestamp( temporalAccessor.getLong( ChronoField.INSTANT_SECONDS ) * 1000L );\n\t\t\t\ttimestamp.setNanos( temporalAccessor.get( ChronoField.NANO_OF_SECOND ) );\n\t\t\t\treturn timestamp;\n\t\t\t}\n\t\t\telse {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java#L209-L245","documentation":"JdbcTimestampJavaType.fromString() parses timestamp literals with the strict pattern 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS' in UTC: a space separator and exactly nine fractional digits are required. Text in ISO form ('2024-01-01T10:00:00'), without nanoseconds, or with fewer/more fraction digits throws DateTimeParseException, wrapped as HibernateException(\"could not parse timestamp string ...\"). Used when HQL timestamp literals are parsed and strings are converted to Timestamp.","triggerScenarios":"HQL literal ... where e.at = '2024-01-01T10:00:00' or '2024-01-01 10:00:00' (missing .000000000); fromString on strings with 'T' separator; passing a String parameter where a Timestamp is expected by the query.","commonSituations":"Devs writing ISO-8601 literals in JPQL (natural habit, wrong format here); front-ends sending ISO strings that get spliced into queries; data feeds formatting timestamps with DateTimeFormatter.ISO_LOCAL_DATE_TIME.","solutions":["Use typed bind parameters (LocalDateTime, Instant or java.sql.Timestamp) instead of string literals - the recommended fix","If a literal is required, format it as 'yyyy-MM-dd HH:mm:ss.fffffffff' with all nine fraction digits (e.g. '2024-01-01 10:00:00.000000000')","Parse the incoming string yourself into a LocalDateTime/Instant and bind the object","For string columns storing timestamps, add an AttributeConverter with the correct formatter"],"exampleFix":"// before\nem.createQuery(\"select e from Log e where e.at = '2024-01-01T10:00:00'\") // HibernateException\n\n// after\nquery = em.createQuery(\"select e from Log e where e.at = :at\", Log.class);\nquery.setParameter(\"at\", LocalDateTime.parse(\"2024-01-01T10:00:00\"));","handlingStrategy":"validation","validationCode":"static final java.time.format.DateTimeFormatter HQL_TS =\n    java.time.format.DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ss.SSSSSSSSS\");\n\nstatic boolean isParsableTimestampLiteral(CharSequence s) {\n    try { HQL_TS.parse(s); return true; }\n    catch (java.time.format.DateTimeParseException e) { return false; }\n}","typeGuard":"static java.time.LocalDateTime tryParseHqlTimestamp(String s) {\n    try { return java.time.LocalDateTime.parse(s.replace(' ', 'T')); }\n    catch (Exception e) { return null; }\n}","tryCatchPattern":"try { /* query with timestamp literal or fromString */ }\ncatch (HibernateException e) {\n    if (e.getCause() instanceof DateTimeParseException)\n        throw new IllegalArgumentException(\"Timestamp literal must be 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS'\", e);\n    throw e;\n}","preventionTips":["Never splice timestamp strings into HQL; bind LocalDateTime/Instant/Timestamp parameters","If a literal is unavoidable, include all 9 fractional digits and a space separator","Parse external ISO strings yourself before use"],"tags":["hibernate","timestamp-parsing","hql-literal","datetimeformatter","utc"],"backgroundTag":"datetime-string-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}