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
- Declare a primary key on the entity: @Id field, @EmbeddedId, or @IdClass
- If the type is not an entity, map it as @Embeddable/@MappedSuperclass instead of @Entity
- 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
- Always declare @Id/@EmbeddedId/@IdClass on every @Entity — no exceptions
- Enable hibernate.hbm2ddl.auto=validate in CI to catch broken mappings at boot
- Review programmatic/dynamic mappings for identifier setup before adding to the boot model
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
- Cannot dereference an entity name
- Class '<componentClassName>' is an '@Embeddable' type and ma
- Property '<propertyName>' may not be annotated '@BatchSize'
- One to many association '<propertyName>' was annotated '@Col
- Collection '<propertyName>' was annotated '@Collate'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/06da2e65166e03f4.
Report an issue: GitHub.