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

  1. Change the <id> to a plain, converter-free basic type (numeric, string, uuid) that matches the column as stored
  2. Or keep that mapping in native hbm.xml and transform only the rest
  3. Or hand-write the mapping.xml id using a plain type and move the conversion into the application layer
  4. 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

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


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/3a1ec80ff6ae4a2a. Report an issue: GitHub.