{"record":{"id":"0888b36155c0b2a5","repo":"hibernate/hibernate-orm","slug":"error-attempting-to-apply-attributeconverter-0888b3","errorCode":null,"errorMessage":"Error attempting to apply AttributeConverter: \" + re.getMessage()","messagePattern":"Error attempting to apply AttributeConverter: \" \\+ re\\.getMessage\\(\\)","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/internal/AttributeConverterInstance.java","lineNumber":60,"sourceCode":"\t\t}\n\t\tcatch (PersistenceException pe) {\n\t\t\tthrow pe;\n\t\t}\n\t\tcatch (RuntimeException re) {\n\t\t\tthrow new PersistenceException( \"Error attempting to apply AttributeConverter\", re );\n\t\t}\n\t}\n\n\t@Override\n\tpublic R toRelationalValue(O domainForm) {\n\t\ttry {\n\t\t\treturn converter.convertToDatabaseColumn( domainForm );\n\t\t}\n\t\tcatch (PersistenceException pe) {\n\t\t\tthrow pe;\n\t\t}\n\t\tcatch (RuntimeException re) {\n\t\t\tthrow new PersistenceException( \"Error attempting to apply AttributeConverter: \" + re.getMessage(), re );\n\t\t}\n\t}\n\n\t@Override\n\tpublic JavaType<O> getDomainJavaType() {\n\t\treturn domainJavaType;\n\t}\n\n\t@Override\n\tpublic JavaType<R> getRelationalJavaType() {\n\t\treturn jdbcJavaType;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object object) {\n\t\tif ( this == object ) {\n\t\t\treturn true;\n\t\t}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/internal/AttributeConverterInstance.java#L42-L78","documentation":"Write-path converter wrapping from AttributeConverterInstance (Hibernate-instantiated converter): any non-PersistenceException RuntimeException thrown by convertToDatabaseColumn during flush or parameter binding is rethrown as this PersistenceException with the original failure as cause.","triggerScenarios":"INSERT/UPDATE of an entity whose converter's convertToDatabaseColumn throws - unhandled null domain value, unmapped enum constant, or an exception from formatting/parsing logic inside the converter.","commonSituations":"Null entity attribute reaching an unguarded converter; enum extended without updating the converter; locale-sensitive formatting failing in CI or another locale; bulk update statements pushing values through the converter.","solutions":["Dereference the cause to find the exact converter failure","Null-guard the converter and cover all domain values","Verify the attribute is not being assigned values of the wrong type before flush","Unit-test the converter with null plus every domain constant"],"exampleFix":"// before\n@Override\npublic String convertToDatabaseColumn(ZonedDateTime v) {\n    return v.format(DateTimeFormatter.ISO_ZONED_DATE_TIME); // NPE on null\n}\n// after\n@Override\npublic String convertToDatabaseColumn(ZonedDateTime v) {\n    return v == null ? null : v.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);\n}","handlingStrategy":"try-catch","validationCode":"// validate before the unit of work that flushes\nObject relational = entity.getValue() == null ? null : converter.convertToDatabaseColumn(entity.getValue());\n// if the line above throws, fix data before persisting","typeGuard":"static <O, R> boolean safeToWrite(AttributeConverter<O, R> c, O value) {\n    try { c.convertToDatabaseColumn(value); return true; }\n    catch (RuntimeException e) { return false; }\n}","tryCatchPattern":"try {\n    tx.executeWithoutResult(s -> session.merge(entity));\n} catch (PersistenceException e) {\n    Throwable root = ExceptionUtils.getRootCause(e);\n    if (root instanceof NullPointerException && entity.getWhen() == null) {\n        entity.setWhen(Instant.now()); // nullable attribute hit an unguarded converter\n        retry in a new transaction;\n    } else throw e;\n}","preventionTips":["Make converters total functions: define output for null and every input","Flush early in request handling so failures map to the offending operation","Property-test converters (jqwik/JQF) over the full domain value set","Avoid locale-dependent formatting inside converters"],"tags":["hibernate","orm","jpa","attribute-converter","persistence-exception","flush"],"backgroundTag":"jpa-attribute-converter-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}