hibernate/hibernate-orm · critical · UnsupportedMappingException

Could not build SqmPathSource for entity identifier: {}

Error message

Could not build SqmPathSource for entity identifier: {}

What it means

Building the SQM path source for an entity's identifier failed: there is no single id attribute, no non-aggregated id-class attributes, and no supertype with an identifier descriptor, yet the mapping requires an id (isIdMappingRequired()). Hibernate throws UnsupportedMappingException — a mapping-level defect, not a query typo: the entity is (or is treated as) identifiable but no id mapping could be derived.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractIdentifiableType.java:443

	private SqmPathSource<?> interpretIdDescriptor() {
		if ( id != null ) {
			// simple id or aggregate composite id
			return pathSource( id );
		}
		else if ( nonAggregatedIdAttributes != null && !nonAggregatedIdAttributes.isEmpty() ) {
			return compositePathSource();
		}

		final var superType = getSuperType();
		if ( superType != null ) {
			final var idDescriptor = superType.getIdentifierDescriptor();
			if ( idDescriptor != null ) {
				return idDescriptor;
			}
		}
		if ( isIdMappingRequired() ) {
			throw new UnsupportedMappingException(
					"Could not build SqmPathSource for entity identifier: " + getTypeName() );
		}
		return null;
	}

	private AbstractSqmPathSource<?> compositePathSource() {
		// non-aggregate composite id
		if ( idClassType == null ) {
			return new NonAggregatedCompositeSqmPathSource<>(
					EntityIdentifierMapping.ID_ROLE_NAME,
					null,
					Bindable.BindableType.SINGULAR_ATTRIBUTE,
					this
			);
		}
		else {
			return new EmbeddedSqmPathSource<>(
					EntityIdentifierMapping.ID_ROLE_NAME,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Declare a primary key on the entity: @Id field, @EmbeddedId, or @IdClass
  2. If the type is not an entity, map it as @Embeddable/@MappedSuperclass instead of @Entity
  3. For programmatic mappings, ensure the identifier attribute is added before the metadata is finalized

Example fix

// before
@Entity
public class AuditLog { LocalDateTime changedAt; } // no @Id

// after
@Entity
public class AuditLog {
    @Id @GeneratedValue Long id;
    LocalDateTime changedAt;
}
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at startup: every @Entity must resolve an identifier
Metamodel mm = entityManagerFactory.getMetamodel();
for (EntityType<?> e : mm.getEntities()) {
    if (e.getIdType() == null && !e.hasIdClass()) {
        throw new IllegalStateException("Entity without id mapping: " + e.getName());
    }
}

Try / catch

try {
    return identifiableType.getIdentifierDescriptor();
} catch (UnsupportedMappingException e) {
    // mapping-level defect: entity requires an id but none could be built
    throw new IllegalStateException("Broken id mapping on " + identifiableType.getTypeName(), e);
}

Prevention

When it happens

Trigger: An @Entity without any @Id/@EmbeddedId/@IdClass declaration; dynamic/programmatic entity builders where the identifier property was never set; embeddables or mapped superclasses routed through getIdentifierDescriptor() although they need ids; incomplete XML (hbm.xml) mappings missing <id>.

Common situations: Creating an entity class and forgetting the primary key (usually schema validation catches this earlier — if you see this at query time, metadata was hand-built or enhanced). Migrating mappings where the id element name changed. Using @Entity on a value class by accident.

Related errors


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