hibernate/hibernate-orm · error · UnsupportedOperationException

No support for parsing UserType values from String: {}

Error message

No support for parsing UserType values from String: {}

What it means

UserTypeJavaTypeWrapper adapts a UserType to the JavaType SPI; its fromString (UserTypeJavaTypeWrapper.java:110-116) delegates only when the user type implements org.hibernate.usertype.EnhancedUserType, and otherwise throws this UnsupportedOperationException. It means some operation needs to turn a String into the custom type's value and your UserType does not expose that capability.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJavaTypeWrapper.java:117

		return comparator;
	}

	@Override
	public int extractHashCode(J value) {
		return userType.hashCode(value );
	}

	@Override
	public boolean areEqual(J one, J another) {
		return userType.equals( one, another );
	}

	@Override
	public J fromString(CharSequence string) {
		if ( userType instanceof EnhancedUserType<J> enhancedUserType ) {
			return enhancedUserType.fromStringValue( string );
		}
		throw new UnsupportedOperationException( "No support for parsing UserType values from String: " + userType );
	}

	@Override
	public String toString(J value) {
		return userType.returnedClass().isInstance( value )
			&& userType instanceof EnhancedUserType<J> enhancedUserType
				? enhancedUserType.toString( value )
				: value == null ? "null" : value.toString();
	}

	@Override
	public <X> X unwrap(J value, Class<X> type, WrapperOptions options) {
		return unwrap( value, type, customType.getValueConverter(), options );
	}

	private <X,R> X unwrap(J value, Class<X> type, BasicValueConverter<J, R> converter, WrapperOptions options) {
		if ( value != null && !type.isInstance( value ) && converter != null ) {
			final Object relationalValue = customType.convertToRelationalValue( value );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Implement EnhancedUserType<J> on your user type - add fromStringValue(CharSequence) and toString(J) - so the adapter can delegate (UserTypeJavaTypeWrapper.java:110-116).
  2. If the type's column is a basic string anyway, replace the UserType with an AttributeConverter, which parses naturally.
  3. Avoid the operation requiring string parsing for that attribute (restructure the mapping or query).

Example fix

// before - plain UserType, string parsing unsupported
public class PostcodeType implements UserType<Postcode> { ... }

// after - EnhancedUserType supplies the missing capability
public class PostcodeType implements UserType<Postcode>, EnhancedUserType<Postcode> {
    @Override public Postcode fromStringValue(CharSequence string) {
        return Postcode.parse( string.toString() );
    }
    @Override public String toString(Postcode value) { return value.asText(); }
    // ... existing UserType methods
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Check capability before string round-trips of UserType-mapped values
if ( !( userType instanceof org.hibernate.usertype.EnhancedUserType<?> ) ) {
    // this type cannot be parsed from a String; avoid such operations
}

Type guard

static boolean parsesFromString(org.hibernate.usertype.UserType<?> userType) {
    return userType instanceof org.hibernate.usertype.EnhancedUserType<?>;
}

Try / catch

try {
    // path that calls JavaType.fromString for the UserType-adapted attribute
} catch ( UnsupportedOperationException e ) {
    if ( e.getMessage() != null && e.getMessage().contains( "No support for parsing UserType values from String" ) ) {
        // implement EnhancedUserType#fromStringValue on the type, then retry
    } else throw e;
}

Prevention

When it happens

Trigger: An attribute mapped with @Type(MyUserType.class) is used where Hibernate parses values from strings (string-based extraction/round-trips, id or natural-id string materialization) while MyUserType implements only the plain UserType interface; the same UserType works for normal persistence but fails the first time a string round-trip is requested.

Common situations: Custom value types written years ago against the plain UserType contract; upgrading Hibernate to a version that starts calling fromString in a new code path; reuse of a legacy UserType for identifier or natural-id mappings.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/2a35af497d4826b3. Report an issue: GitHub.