{"record":{"id":"0b04bce5bc183af6","repo":"hibernate/hibernate-orm","slug":"no-support-for-parsing-usertype-values-from-string","errorCode":null,"errorMessage":"No support for parsing UserType values from String: {}","messagePattern":"No support for parsing UserType values from String: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/internal/CompositeUserTypeJavaTypeWrapper.java","lineNumber":99,"sourceCode":"\n\t@Override\n\tpublic Comparator<J> getComparator() {\n\t\treturn comparator;\n\t}\n\n\t@Override\n\tpublic int extractHashCode(J value) {\n\t\treturn userType.hashCode(value );\n\t}\n\n\t@Override\n\tpublic boolean areEqual(J one, J another) {\n\t\treturn userType.equals( one, another );\n\t}\n\n\t@Override\n\tpublic J fromString(CharSequence string) {\n\t\tthrow new UnsupportedOperationException( \"No support for parsing UserType values from String: \" + userType );\n\t}\n\n\t@Override\n\tpublic <X> X unwrap(J value, Class<X> type, WrapperOptions options) {\n\t\tassert value == null || userType.returnedClass().isInstance( value );\n\t\treturn type.cast( value );\n\t}\n\n\t@Override\n\tpublic <X> J wrap(X value, WrapperOptions options) {\n//\t\tassert value == null || userType.returnedClass().isInstance( value );\n\t\t//noinspection unchecked\n\t\treturn (J) value;\n\t}\n\n\t@Override\n\tpublic Class<J> getJavaTypeClass() {\n\t\treturn userType.returnedClass();","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/internal/CompositeUserTypeJavaTypeWrapper.java#L81-L117","documentation":"CompositeUserTypeJavaTypeWrapper adapts a CompositeUserType to Hibernate's JavaType SPI; its fromString (CompositeUserTypeJavaTypeWrapper.java:96-99) throws unconditionally because the CompositeUserType contract has no hook for parsing a value from its string form. The error surfaces whenever an operation requires materializing an @CompositeType attribute from a String representation, which composite user types simply cannot support.","triggerScenarios":"Using an attribute mapped with @CompositeType(MyCompositeType.class) in a context where Hibernate asks the JavaType to parse a String (string-based result extraction, string-representable id/natural-id lookups, APIs that need JavaType.fromString); any custom code that calls javaType.fromString on the adapted descriptor.","commonSituations":"Switching an embeddable to a CompositeUserType and then needing string round-trips the embeddable used to provide; integrations or query features that assume every JavaType can parse its toString output.","solutions":["Identify and remove the operation that needs string parsing for the @CompositeType attribute (restructure the query/lookup to avoid string round-trips).","If string parsing is a hard requirement, replace the CompositeUserType with a plain UserType that implements EnhancedUserType, or with an AttributeConverter on a basic column type.","Map the structure as a regular @Embeddable instead of a CompositeUserType - embeddables support component-based construction.","Catch UnsupportedOperationException at the call site and degrade gracefully if the operation is optional."],"exampleFix":"// before - composite user type cannot be built from a String\npublic class AddressType implements CompositeUserType<Address> { ... }\n// any Hibernate path calling javaType.fromString(...) -> UnsupportedOperationException\n\n// after - use an AttributeConverter that parses from the stored string\n@Converter\npublic class AddressConverter implements AttributeConverter<Address, String> {\n    @Override public String convertToDatabaseColumn(Address a) { return a == null ? null : a.toLine(); }\n    @Override public Address convertToEntityAttribute(String s) { return s == null ? null : Address.parse(s); }\n}","handlingStrategy":"try-catch","validationCode":"// Before relying on string round-trips of a @CompositeType attribute,\n// verify the capability exists on its JavaType:\nJavaType<?> jt = sessionFactory.getTypeConfiguration()\n        .getJavaTypeRegistry()\n        .resolveDescriptor( MyCompositeType.returnedClass() );\nif ( !StringRepresentableType.class.isInstance( jt ) ) {\n    // avoid operations that need fromString() for this attribute\n}","typeGuard":null,"tryCatchPattern":"try {\n    // operation that may need to materialize the composite value from a String\n} catch ( UnsupportedOperationException e ) {\n    if ( e.getMessage() != null && e.getMessage().startsWith( \"No support for parsing UserType values\" ) ) {\n        // fall back to a query/lookup strategy that does not require string parsing\n    } else throw e;\n}","preventionTips":["Do not use @CompositeType attributes where string round-trips (string ids, string-based extraction) are needed - use an AttributeConverter or plain UserType instead.","Document per attribute type whether string parsing is supported.","Add integration tests covering every lookup style used with custom types."],"tags":["hibernate","usertype","composite-type","mapping","orm"],"backgroundTag":"custom-type-string-parsing-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}