{"record":{"id":"c3379edf2109a1cd","repo":"hibernate/hibernate-orm","slug":"schema-validation-wrong-column-type-encountered-i","errorCode":null,"errorMessage":"Schema validation: wrong column type encountered in column [%s] in table [%s]; found [%s (Types#%s)], but expecting [%s (Types#%s)]","messagePattern":"Schema validation: wrong column type encountered in column \\[(.+?)\\] in table \\[(.+?)\\]; found \\[(.+?) \\(Types#(.+?)\\)\\], but expecting \\[(.+?) \\(Types#(.+?)\\)\\]","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java","lineNumber":162,"sourceCode":"\t\t\t\t\t\t\t\ttable.getQualifiedTableName()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t\tvalidateColumnType( table, column, existingColumn, metadata, dialect );\n\t\t}\n\n\t\tvalidateIndexes( table, tableInformation, metadata, options, dialect );\n\t\tvalidateUniqueKeys( table, tableInformation, metadata, options, dialect );\n\t}\n\n\tprotected void validateColumnType(\n\t\t\tTable table,\n\t\t\tColumn column,\n\t\t\tColumnInformation columnInformation,\n\t\t\tMetadata metadata,\n\t\t\tDialect dialect) {\n\t\tif ( !hasMatchingType( column, columnInformation, metadata, dialect ) ) {\n\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"Schema validation: wrong column type encountered in column [%s] in \" +\n\t\t\t\t\t\t\t\t\t\"table [%s]; found [%s (Types#%s)], but expecting [%s (Types#%s)]\",\n\t\t\t\t\t\t\tcolumn.getName(),\n\t\t\t\t\t\t\ttable.getQualifiedTableName(),\n\t\t\t\t\t\t\tcolumnInformation.getTypeName().toLowerCase( ROOT),\n\t\t\t\t\t\t\tJdbcTypeNameMapper.getTypeName( columnInformation.getTypeCode() ),\n\t\t\t\t\t\t\tcolumn.getSqlType( metadata ).toLowerCase( ROOT),\n\t\t\t\t\t\t\tJdbcTypeNameMapper.getTypeName( column.getSqlTypeCode( metadata ) )\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate void validateIndexes(\n\t\t\tTable table,\n\t\t\tTableInformation tableInformation,\n\t\t\tMetadata metadata,","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java#L144-L180","documentation":"Schema validation matched a column by name but the JDBC type disagrees with the entity/dialect expectation: found [<db type name> (Types#<db code>)] but expecting [<mapped sql type> (Types#<mapped code>)]. The comparison resolves the mapped type through the dialect, so a mismatch means the physical column type genuinely differs (INTEGER vs BIGINT, VARCHAR vs CLOB/UUID/BINARY) or the configured dialect does not match the database.","triggerScenarios":"hibernate.hbm2ddl.auto=validate with column-type drift: entity uses Long/@GeneratedValue but the DB column is INTEGER; String/@Lob against varchar instead of text/clob; UUID mappings needing uuid/binary(16) columns; dialect mismatch (H2Dialect against PostgreSQL, wrong hibernate.dialect); drivers reporting Types.OTHER for proprietary types (json, jsonb) without a matching @JdbcTypeCode mapping.","commonSituations":"A manual ALTER TABLE changed a column type; migrating between database vendors without regenerating the schema; Hibernate upgrade changing default type mappings (e.g. UUID, duration, instant); test profile using H2 while production uses Postgres; jsonb columns used without the proper dialect support.","solutions":["Change the physical column type to what the mapping expects: ALTER TABLE ... ALTER COLUMN ... TYPE bigint (or equivalent).","Or adjust the mapping to the physical type: explicit @JdbcType/@JdbcTypeCode, @Column(columnDefinition=...), or change the field type.","Verify hibernate.dialect matches the actual database (or remove it and let Hibernate 6+ autodetect).","Rerun validation after the fix; keep the fix as a migration so all environments converge."],"exampleFix":"// before: entity expects bigint (Types#BIGINT) but the DB column is integer (Types#INTEGER)\n@Id @GeneratedValue(strategy = GenerationType.IDENTITY)\nprivate Long id;\n\n// after: migrate the column type, mapping unchanged\n// ALTER TABLE customer ALTER COLUMN id TYPE bigint;\n@Id @GeneratedValue(strategy = GenerationType.IDENTITY)\nprivate Long id;","handlingStrategy":"validation","validationCode":"// Pre-check the JDBC type of critical columns matches expectation (java.sql.Types codes)\ntry (Connection c = dataSource.getConnection()) {\n    DatabaseMetaData md = c.getMetaData();\n    try (ResultSet rs = md.getColumns(null, null, \"customer\", \"id\")) {\n        if (rs.next() && rs.getInt(\"DATA_TYPE\") != java.sql.Types.BIGINT) {\n            throw new IllegalStateException(\"customer.id is not BIGINT - migrate the column before validate\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new SchemaValidator().validate(metadata, serviceRegistry);\n} catch (SchemaManagementException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"wrong column type\")) {\n        // message contains found vs expecting types: migrate the column, adjust @JdbcType/@Column, or fix the dialect\n    }\n    throw e;\n}","preventionTips":["Use the correct dialect for the target database (or let Hibernate 6+ autodetect)","Never rely on auto-generated DDL in production; generate and review migrations with matching types","Watch type-mapping changes when upgrading Hibernate major versions; re-run validate in CI immediately after"],"tags":["hibernate","schema-validation","hbm2ddl","column-type","dialect"],"backgroundTag":"column-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}