hibernate/hibernate-orm · error · MappingException
Error creating SQL create commands for UDT :
Error message
Error creating SQL create commands for UDT :
What it means
While building the CREATE TYPE statement for an object UDT, StandardUserDefinedTypeExporter wraps any exception (name formatting, attribute column rendering, dialect extension strings) into this MappingException carrying the type name. As with the table exporter, it is a wrapper: the real failure is the nested cause, typically an attribute type the dialect cannot render inside the UDT.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUserDefinedTypeExporter.java:86
if ( isFirst ) {
isFirst = false;
}
else {
createType.append( ", " );
}
createType.append( col.getQuotedName( dialect ) );
createType.append( ' ' ).append( col.getSqlType( metadata ) );
}
createType.append( ')' );
applyUserDefinedTypeExtensionsString( createType );
List<String> sqlStrings = new ArrayList<>();
sqlStrings.add( createType.toString() );
applyComments( userDefinedType, formattedTypeName, sqlStrings );
return sqlStrings.toArray(StringHelper.EMPTY_STRINGS);
}
catch (Exception e) {
throw new MappingException( "Error creating SQL create commands for UDT : " + typeName, e );
}
}
public String[] getSqlCreateStrings(
UserDefinedArrayType userDefinedType,
Metadata metadata,
SqlStringGenerationContext context) {
throw new IllegalArgumentException( "Exporter does not support name array types. Can't generate create strings for: " + userDefinedType );
}
/**
* @param udt The UDT.
* @param formattedTypeName The formatted UDT name.
* @param sqlStrings The list of SQL strings to add comments to.
*/
protected void applyComments(UserDefinedObjectType udt, String formattedTypeName, List<String> sqlStrings) {
if ( dialect.supportsCommentOn() ) {
final String comment = udt.getComment();View on GitHub (pinned to fad1729dce)
Solutions
- Inspect the cause exception and the type name in the message; fix the specific attribute mapping that fails to render (usually columnDefinition/length/JdbcType inside the embeddable).
- Confirm the target dialect supports object UDTs and that the mapping matches its capabilities.
- If the type is created out-of-band by DBA scripts, remove it from hbm2ddl generation instead of forcing export.
Example fix
// before: UDT attribute with a dialect-specific definition
@Embeddable
public class Address {
@Column(columnDefinition = "nvarchar(max)")
private String city;
}
// after: portable attribute; the dialect renders its own type
@Embeddable
public class Address {
@Column(length = 255)
private String city;
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight render to STDOUT/SCRIPT without a database connection; UDT render failures surface here
new SchemaExport(metadata).setOutputFile("ddl.sql").createOnly(); Try / catch
try {
exporter.getSqlCreateStrings(userDefinedObjectType, metadata, context);
} catch (MappingException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Error creating SQL create commands for UDT :")) {
Throwable root = e; while (root.getCause() != null) root = root.getCause();
// fix the failing attribute mapping inside the embeddable/UDT based on `root`
} else { throw e; }
} Prevention
- Keep UDT attribute types portable across dialects; avoid vendor columnDefinition inside embeddables used as UDTs.
- Validate UDT mappings with a connection-less script export in CI.
- Re-test UDT export after Hibernate or dialect upgrades.
When it happens
Trigger: Object UDT export where rendering fails: an @Embeddable mapped as a UDT with an attribute whose sqlType/columnDefinition the dialect rejects at render time, quoting/format issues with catalog/schema/name parts, dialect option lookups failing in applyUserDefinedTypeExtensionsString, or programmatic UDT metadata with inconsistent attribute definitions.
Common situations: Hibernate 6 structured-type mappings on Oracle/PostgreSQL/H2 with dialect mismatches; Hibernate upgrades changing UDT rendering; embeddable attributes tuned for another database; UDT attributes with huge lengths or exotic @JdbcType values.
Related errors
- Database does not support user-defined types (remove '@Struc
- unknown type: {sqlTypeCode}
- Unable to determine SQL type name for column '%s' of table '
- Error creating SQL 'create' commands for table '
- Exporter does not support name array types. Can't generate c
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/038dfa7f3fad6713.
Report an issue: GitHub.