{"record":{"id":"038dfa7f3fad6713","repo":"hibernate/hibernate-orm","slug":"error-creating-sql-create-commands-for-udt","errorCode":null,"errorMessage":"Error creating SQL create commands for UDT : ","messagePattern":"Error creating SQL create commands for UDT : ","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUserDefinedTypeExporter.java","lineNumber":86,"sourceCode":"\t\t\t\tif ( isFirst ) {\n\t\t\t\t\tisFirst = false;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tcreateType.append( \", \" );\n\t\t\t\t}\n\t\t\t\tcreateType.append( col.getQuotedName( dialect ) );\n\t\t\t\tcreateType.append( ' ' ).append( col.getSqlType( metadata ) );\n\t\t\t}\n\t\t\tcreateType.append( ')' );\n\t\t\tapplyUserDefinedTypeExtensionsString( createType );\n\n\t\t\tList<String> sqlStrings = new ArrayList<>();\n\t\t\tsqlStrings.add( createType.toString() );\n\t\t\tapplyComments( userDefinedType, formattedTypeName, sqlStrings );\n\t\t\treturn sqlStrings.toArray(StringHelper.EMPTY_STRINGS);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new MappingException( \"Error creating SQL create commands for UDT : \" + typeName, e );\n\t\t}\n\t}\n\n\tpublic String[] getSqlCreateStrings(\n\t\t\tUserDefinedArrayType userDefinedType,\n\t\t\tMetadata metadata,\n\t\t\tSqlStringGenerationContext context) {\n\t\tthrow new IllegalArgumentException( \"Exporter does not support name array types. Can't generate create strings for: \" + userDefinedType );\n\t}\n\n\t/**\n\t * @param udt The UDT.\n\t * @param formattedTypeName The formatted UDT name.\n\t * @param sqlStrings The list of SQL strings to add comments to.\n\t */\n\tprotected void applyComments(UserDefinedObjectType udt, String formattedTypeName, List<String> sqlStrings) {\n\t\tif ( dialect.supportsCommentOn() ) {\n\t\t\tfinal String comment = udt.getComment();","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUserDefinedTypeExporter.java#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: UDT attribute with a dialect-specific definition\n@Embeddable\npublic class Address {\n    @Column(columnDefinition = \"nvarchar(max)\")\n    private String city;\n}\n\n// after: portable attribute; the dialect renders its own type\n@Embeddable\npublic class Address {\n    @Column(length = 255)\n    private String city;\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight render to STDOUT/SCRIPT without a database connection; UDT render failures surface here\nnew SchemaExport(metadata).setOutputFile(\"ddl.sql\").createOnly();","typeGuard":null,"tryCatchPattern":"try {\n    exporter.getSqlCreateStrings(userDefinedObjectType, metadata, context);\n} catch (MappingException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error creating SQL create commands for UDT :\")) {\n        Throwable root = e; while (root.getCause() != null) root = root.getCause();\n        // fix the failing attribute mapping inside the embeddable/UDT based on `root`\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["hibernate","udt","user-defined-type","ddl","mapping","dialect"],"backgroundTag":"ddl-generation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}