{"record":{"id":"ecde02afa2b5445f","repo":"hibernate/hibernate-orm","slug":"error-creating-sql-create-commands-for-table","errorCode":null,"errorMessage":"Error creating SQL 'create' commands for table '","messagePattern":"Error creating SQL 'create' commands for table '","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java","lineNumber":72,"sourceCode":"\t\t\tTable table,\n\t\t\tMetadata metadata,\n\t\t\tSqlStringGenerationContext context) {\n\t\tfinal var tableName = getTableName( table );\n\t\ttry {\n\t\t\tfinal String formattedTableName = context.format( tableName );\n\t\t\tfinal String ddl =\n\t\t\t\t\ttable.isView()\n\t\t\t\t\t\t\t? appendCreateView( table, formattedTableName )\n\t\t\t\t\t\t\t: appendCreateTable( table, formattedTableName, metadata, context );\n\n\t\t\tfinal List<String> sqlStrings = new ArrayList<>();\n\t\t\tsqlStrings.add( ddl );\n\t\t\tapplyComments( table, formattedTableName, sqlStrings );\n\t\t\tapplyInitCommands( table, sqlStrings, context );\n\t\t\treturn sqlStrings.toArray( EMPTY_STRINGS );\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new MappingException( \"Error creating SQL 'create' commands for table '\"\n\t\t\t\t\t+ table.getName() + \"' [\" + e.getMessage() + \"]\" , e );\n\t\t}\n\t}\n\n\tprivate static void appendOptions(Table table, StringBuilder createTable) {\n\t\tfinal String options = table.getOptions();\n\t\tif ( isNotBlank( options ) ) {\n\t\t\tcreateTable.append( \" \" ).append( options );\n\t\t}\n\t}\n\n\tprivate String appendCreateTable(Table table, String tableName, Metadata metadata, SqlStringGenerationContext context) {\n\t\tfinal var createTable = new StringBuilder();\n\t\tfinal var extra = new StringBuilder();\n\n\t\tcreateTable.append( tableCreateString( table ) )\n\t\t\t\t.append( ' ' )\n\t\t\t\t.append( tableName )","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java#L54-L90","documentation":"StandardTableExporter wraps every exception thrown while composing the CREATE TABLE/VIEW statement for one table into a MappingException prefixed with this message, appending the table name and the original exception's message. It is an umbrella: the actionable information is the bracketed suffix and the nested cause, typically a column type/definition problem or a dialect capability mismatch discovered while rendering the table.","triggerScenarios":"Any exception while rendering create-DDL for a table: a column length/type the dialect cannot render (e.g., varchar length exceeding the dialect limit), invalid @Column(columnDefinition=...) interacting with dialect type resolution, unsupported identity/id-generation settings for the dialect, dialect option lookups failing during appendCreateTable, or a programmatically built Table with inconsistent column/type metadata. Surfaces during hbm2ddl create, SchemaExport, or create-drop startup.","commonSituations":"Porting an app to another database (H2/SQLServer/Oracle) with mappings tuned for the original DB; Hibernate or dialect upgrades that change type rendering; @Column(length = ...) values above the new dialect's limit; entities with exotic @JdbcType/@JdbcTypeCode combinations; views with options the dialect rejects.","solutions":["Read the bracketed suffix and the caused-by stack trace; fix that root problem (usually a specific column mapping), not the wrapper.","Make the offending mapping dialect-portable: drop hard-coded columnDefinition, use @JdbcTypeCode(SqlTypes.LONGVARCHAR) (or similar) for very long strings instead of huge lengths.","Verify the dialect matches the actual database version; prefer letting Hibernate detect it rather than pinning an old dialect.","Isolate the table by exporting with TargetType.STDOUT to inspect the partially rendered SQL and confirm the fix."],"exampleFix":"// before\n@Column(length = 10_000_000) // exceeds the dialect's varchar limit -> type render throws, wrapped here\nprivate String body;\n\n// after\n@JdbcTypeCode(SqlTypes.LONGVARCHAR) // dialect renders its own large-text type\nprivate String body;","handlingStrategy":"try-catch","validationCode":"// cheap pre-flight: export all mappings to STDOUT only; render errors surface here without touching a DB\nnew SchemaExport(metadata).createOnly(EnumSet.of(TargetType.STDOUT));","typeGuard":null,"tryCatchPattern":"try {\n    new SchemaExport(metadata).createOnly();\n} catch (MappingException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error creating SQL 'create' commands for table\")) {\n        Throwable root = e; while (root.getCause() != null) root = root.getCause();\n        // fix the mapping named by the table in the message based on `root`\n    } else { throw e; }\n}","preventionTips":["Keep column mappings dialect-portable; avoid hard-coded columnDefinition.","Run stdout-only schema export in CI against the production-like database version.","Re-run mapping smoke tests after dialect or Hibernate upgrades."],"tags":["hibernate","ddl","table","mapping","dialect","schema-generation"],"backgroundTag":"ddl-generation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}