hibernate/hibernate-orm · error · UnsupportedOperationException

Unsupported identifier type:

Error message

Unsupported identifier type: 

What it means

Inside a JSON aggregate Hibernate serializes referenced entities as just their identifier (serializeEntity -> serializeEntityIdentifier). It can write identifiers whose EntityIdentifierMapping is a SingleAttributeIdentifierMapping (simple @Id and single-attribute @EmbeddedId). The fallback branch only accepts an identifier VALUE that is itself a CompositeIdentifierMapping - which effectively never happens, since getIdentifier(value) returns the user's id object, not a mapping - so any other identifier shape throws UnsupportedOperationException naming the identifier's class.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/spi/JsonGeneratingVisitor.java:304

	protected void serializeEntityIdentifier(
			Object value,
			EntityIdentifierMapping identifierMapping,
			WrapperOptions options,
			JsonDocumentWriter writer) throws IOException {
		final Object identifier = identifierMapping.getIdentifier( value );
		if ( identifierMapping instanceof SingleAttributeIdentifierMapping singleAttribute ) {
			writer.serializeJsonValue(
					identifier,
					singleAttribute.getJavaType(),
					singleAttribute.getSingleJdbcMapping().getJdbcType(),
					options
			);
		}
		else if ( identifier instanceof CompositeIdentifierMapping composite ) {
			visit( composite.getMappedType(), identifier, options, writer );
		}
		else {
			throw new UnsupportedOperationException(
					"Unsupported identifier type: " + identifier.getClass().getName() );
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Switch the referenced entity to @EmbeddedId (single-attribute composite id) or a simple @Id
  2. Do not reference the entity from the JSON aggregate - store basic FK value(s) (one column per id field) inside the embeddable instead
  3. Upgrade Hibernate ORM - identifier serialization for aggregates keeps being extended; report the case if it persists

Example fix

// before
class OrderUserId implements Serializable { Long tenantId; Long seq; } // @IdClass
@Entity @IdClass(OrderUserId.class)
class OrderUser { @Id Long tenantId; @Id Long seq; }

// after
@Entity
class OrderUser {
    @EmbeddedId
    private OrderUserId id; // single-attribute composite id serializes inside JSON aggregates
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify every entity referenced from JSON aggregates has a single-attribute id
for (EntityBinding b : referencedEntities) {
    if (b.idUsesIdClass()) { // detected via @IdClass on the entity class
        throw new IllegalStateException("Entity " + b.name + " with @IdClass cannot be referenced from a JSON aggregate");
    }
}

Prevention

When it happens

Trigger: A to-one reference (or element mapping) inside a JSON aggregate pointing at an entity whose primary key uses @IdClass (non-aggregated composite id): identifierMapping is not single-attribute and getIdentifier(value) returns the IdClass instance, so the else branch fires. Custom EntityIdentifierMapping implementations hit it too.

Common situations: Legacy schemas with @IdClass entities pulled into newer JSON aggregate mappings; embedding references to composite-key entities inside jsonb/OSON columns; migrating models to JSON storage while keeping @IdClass.

Related errors


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