hibernate/hibernate-orm · error · SchemaManagementException
Schema validation: wrong column type encountered in column [
Error message
Schema validation: wrong column type encountered in column [%s] in table [%s]; found [%s (Types#%s)], but expecting [%s (Types#%s)]
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java:162
table.getQualifiedTableName()
)
);
}
validateColumnType( table, column, existingColumn, metadata, dialect );
}
validateIndexes( table, tableInformation, metadata, options, dialect );
validateUniqueKeys( table, tableInformation, metadata, options, dialect );
}
protected void validateColumnType(
Table table,
Column column,
ColumnInformation columnInformation,
Metadata metadata,
Dialect dialect) {
if ( !hasMatchingType( column, columnInformation, metadata, dialect ) ) {
throw new SchemaManagementException(
String.format(
"Schema validation: wrong column type encountered in column [%s] in " +
"table [%s]; found [%s (Types#%s)], but expecting [%s (Types#%s)]",
column.getName(),
table.getQualifiedTableName(),
columnInformation.getTypeName().toLowerCase( ROOT),
JdbcTypeNameMapper.getTypeName( columnInformation.getTypeCode() ),
column.getSqlType( metadata ).toLowerCase( ROOT),
JdbcTypeNameMapper.getTypeName( column.getSqlTypeCode( metadata ) )
)
);
}
}
private void validateIndexes(
Table table,
TableInformation tableInformation,
Metadata metadata,View on GitHub (pinned to fad1729dce)
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.
Example fix
// before: entity expects bigint (Types#BIGINT) but the DB column is integer (Types#INTEGER) @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; // after: migrate the column type, mapping unchanged // ALTER TABLE customer ALTER COLUMN id TYPE bigint; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check the JDBC type of critical columns matches expectation (java.sql.Types codes)
try (Connection c = dataSource.getConnection()) {
DatabaseMetaData md = c.getMetaData();
try (ResultSet rs = md.getColumns(null, null, "customer", "id")) {
if (rs.next() && rs.getInt("DATA_TYPE") != java.sql.Types.BIGINT) {
throw new IllegalStateException("customer.id is not BIGINT - migrate the column before validate");
}
}
} Try / catch
try {
new SchemaValidator().validate(metadata, serviceRegistry);
} catch (SchemaManagementException e) {
if (e.getMessage() != null && e.getMessage().contains("wrong column type")) {
// message contains found vs expecting types: migrate the column, adjust @JdbcType/@Column, or fix the dialect
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unrecognized 'hibernate.hbm2ddl.jdbc_metadata_extraction_str
- Schema validation: missing table [%s]
- Schema validation: missing column [%s] in table [%s]
- Missing index named `%s` on table `%s`
- Index mismatch - `%s` on table `%s`
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c3379edf2109a1cd.
Report an issue: GitHub.