hibernate/hibernate-orm · error · MappingException
Unable to resolve Hibernate type for column '%s' of table '%
Error message
Unable to resolve Hibernate type for column '%s' of table '%s'
What it means
To resolve a column's Hibernate type, Column walks the owning value's type, accumulating each sub-type's column span to find which sub-type covers the given column index. When the spans never cover the column — an extra column or formula inside a component, a wrong typeIndex, or misordered multi-column types — resolution fails with this MappingException naming the column and table.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/mapping/Column.java:487
if ( typeStartIndex + columnSpan > typeIndex ) {
final int subtypeIndex = typeIndex - typeStartIndex;
if ( subtype instanceof EntityType ) {
return getTypeForEntityValue( mappingContext, subtype, subtypeIndex );
}
else if ( subtype instanceof ComponentType componentType ) {
return getTypeForComponentValue( mappingContext, componentType, subtypeIndex );
}
else if ( subtypeIndex == 0 ) {
return subtype;
}
else {
break;
}
}
typeStartIndex += columnSpan;
}
throw new MappingException(
String.format(
Locale.ROOT,
"Unable to resolve Hibernate type for column '%s' of table '%s'",
getName(),
getValue().getTable().getName()
)
);
}
private Type getTypeForEntityValue(MappingContext mappingContext, Type type, int typeIndex) {
int index = 0;
if ( type instanceof EntityType entityType ) {
return getTypeForEntityValue(
mappingContext,
entityType.getIdentifierOrUniqueKeyType( mappingContext ),
typeIndex
);
}View on GitHub (pinned to fad1729dce)
Solutions
- Make each component sub-mapping declare exactly the columns its type spans, in order.
- Remove stray columns or formulas that no sub-type owns.
- For multi-column custom types, order @Columns entries to match the type's column order.
Example fix
<!-- before: extra selectable with no type span -->
<component name="addr">
<property name="zip" column="zip"/>
<formula>upper(street)</formula>
</component>
<!-- after -->
<component name="addr">
<property name="zip" column="zip"/>
<property name="street" column="street"/>
</component> Defensive patterns
Strategy: validation
Try / catch
try {
SessionFactory sf = configuration.buildSessionFactory();
}
catch ( MappingException e ) {
// message: Unable to resolve Hibernate type for column '<col>' of table '<tbl>'
// check that every column inside the owning component is covered by a sub-type span
} Prevention
- Declare columns in the exact order of the owning type's column spans
- Remove orphan columns/formulas when changing component fields
- Prefer annotations over hand-written hbm components to keep spans consistent
When it happens
Trigger: A component/embeddable mapping with more <column>/<formula> entries than the component's types span; @Columns on a multi-column custom type in the wrong position relative to typeIndex; formulas inside composite elements offsetting spans; generated mappings emitting stale column lists.
Common situations: Hand-maintained hbm components; switching an attribute between a basic type and a multi-column custom type; code generators that do not regenerate join column lists after model changes.
Related errors
- Secondary table '${explicitTableName}' for property '${prope
- The INSERT statement for table [%s] contains no column, and
- cannot recreate collection while filter is enabled: " + coll
- cannot recreate collection while filter is enabled [%s : %s]
- '@AttributeAccessor' annotation must specify a 'strategy'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/36d3959a3033348b.
Report an issue: GitHub.