hibernate/hibernate-orm · error · UnsupportedOperationException
Conversion of id attributes not supported
Error message
Conversion of id attributes not supported
What it means
During transformation of an hbm.xml <id> property, applyBasicTypeMapping is given a callback that rejects converters. If the resolved BasicValue for the identifier carries a value converter (a converter-backed basic type), the callback throws UnsupportedOperationException - id attributes that require relational<->domain conversion are explicitly unsupported by the transformer.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java:4123
private JaxbIdImpl transformNonAggregatedKeyProperty(
JaxbHbmCompositeKeyBasicAttributeType hbmIdProperty,
PropertyInfo idPropertyInfo) {
final var jaxbBasic = new JaxbIdImpl();
jaxbBasic.setName( hbmIdProperty.getName() );
transferAccess(
hbmIdProperty.getAccess(),
jaxbBasic::setAccess,
jaxbBasic::setAttributeAccessor
);
applyBasicTypeMapping(
(BasicValue) idPropertyInfo.bootModelProperty().getValue(),
jaxbBasic,
hbmIdProperty.getTypeAttribute(),
hbmIdProperty.getType(),
null,
basicValueConverter -> {
throw new UnsupportedOperationException( "Conversion of id attributes not supported" );
}
);
transferColumnsAndFormulas(
idPropertyInfo,
new ColumnAndFormulaSource() {
@Override
public String getColumnAttribute() {
return hbmIdProperty.getColumnAttribute();
}
@Override
public String getFormulaAttribute() {
return null;
}
@Override
public List<Serializable> getColumnOrFormula() {View on GitHub (pinned to fad1729dce)
Solutions
- Change the <id> to a plain, converter-free basic type (numeric, string, uuid) that matches the column as stored
- Or keep that mapping in native hbm.xml and transform only the rest
- Or hand-write the mapping.xml id using a plain type and move the conversion into the application layer
- If the encoded storage is a hard requirement, keep the whole mapping on hbm.xml/annotations instead of transformation
Example fix
<!-- before --> <id name="activeFlag" type="yes_no" column="active_flag"/> <!-- after: use the raw representation; convert in code if needed --> <id name="activeFlag" type="string" column="active_flag" length="1"/>
Defensive patterns
Strategy: try-catch
Validate before calling
// flag converter-backed types on <id> before transform (yes_no, converted customs, ...)
var ids = doc.getElementsByTagName("id");
Set<String> converterBacked = Set.of("yes_no", "true_false", "numeric_boolean", "char_boolean");
for (int i = 0; i < ids.getLength(); i++) {
String t = ((org.w3c.dom.Element) ids.item(i)).getAttribute("type");
if (converterBacked.contains(t)) {
throw new IllegalStateException("<id> uses converter-backed type '" + t + "' - not transformable");
}
} Try / catch
try {
transformer.transform(hbmSource);
} catch (UnsupportedOperationException e) {
if (e.getMessage().contains("Conversion of id attributes")) {
// change the id to a plain basic type or keep this mapping native hbm.xml
}
throw e;
} Prevention
- Avoid converter-backed types on identifiers in hbm destined for transformation
- Audit ids stored as encoded characters (Y/N, T/F) before migration
- Move value conversion for ids into application code or DB defaults
When it happens
Trigger: An <id> whose 'type' resolves to a converted basic type - e.g. legacy converter-backed types such as yes/no character encoding, numeric-encoded enums, or any custom AttributeConverter-backed type registered for the id column.
Common situations: Legacy schemas storing boolean ids as CHAR(1) 'Y'/'N' with type="yes_no"; ids stored encoded (e.g. 'M'/'F' style codes) via custom types; migration of such mappings to mapping.xml.
Related errors
- Error transforming element-collection :
- Error transforming one-to-many :
- Error transforming many-to-many :
- Error transforming many-to-any :
- Unexpected node type -
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3a1ec80ff6ae4a2a.
Report an issue: GitHub.