{"record":{"id":"06da2e65166e03f4","repo":"hibernate/hibernate-orm","slug":"could-not-build-sqmpathsource-for-entity-identifie","errorCode":null,"errorMessage":"Could not build SqmPathSource for entity identifier: {}","messagePattern":"Could not build SqmPathSource for entity identifier: (.+?)","errorType":"exception","errorClass":"UnsupportedMappingException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractIdentifiableType.java","lineNumber":443,"sourceCode":"\n\tprivate SqmPathSource<?> interpretIdDescriptor() {\n\t\tif ( id != null ) {\n\t\t\t// simple id or aggregate composite id\n\t\t\treturn pathSource( id );\n\t\t}\n\t\telse if ( nonAggregatedIdAttributes != null && !nonAggregatedIdAttributes.isEmpty() ) {\n\t\t\treturn compositePathSource();\n\t\t}\n\n\t\tfinal var superType = getSuperType();\n\t\tif ( superType != null ) {\n\t\t\tfinal var idDescriptor = superType.getIdentifierDescriptor();\n\t\t\tif ( idDescriptor != null ) {\n\t\t\t\treturn idDescriptor;\n\t\t\t}\n\t\t}\n\t\tif ( isIdMappingRequired() ) {\n\t\t\tthrow new UnsupportedMappingException(\n\t\t\t\t\t\"Could not build SqmPathSource for entity identifier: \" + getTypeName() );\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate AbstractSqmPathSource<?> compositePathSource() {\n\t\t// non-aggregate composite id\n\t\tif ( idClassType == null ) {\n\t\t\treturn new NonAggregatedCompositeSqmPathSource<>(\n\t\t\t\t\tEntityIdentifierMapping.ID_ROLE_NAME,\n\t\t\t\t\tnull,\n\t\t\t\t\tBindable.BindableType.SINGULAR_ATTRIBUTE,\n\t\t\t\t\tthis\n\t\t\t);\n\t\t}\n\t\telse {\n\t\t\treturn new EmbeddedSqmPathSource<>(\n\t\t\t\t\tEntityIdentifierMapping.ID_ROLE_NAME,","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractIdentifiableType.java#L425-L461","documentation":"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.","triggerScenarios":"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>.","commonSituations":"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.","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"],"exampleFix":"// before\n@Entity\npublic class AuditLog { LocalDateTime changedAt; } // no @Id\n\n// after\n@Entity\npublic class AuditLog {\n    @Id @GeneratedValue Long id;\n    LocalDateTime changedAt;\n}","handlingStrategy":"validation","validationCode":"// Fail fast at startup: every @Entity must resolve an identifier\nMetamodel mm = entityManagerFactory.getMetamodel();\nfor (EntityType<?> e : mm.getEntities()) {\n    if (e.getIdType() == null && !e.hasIdClass()) {\n        throw new IllegalStateException(\"Entity without id mapping: \" + e.getName());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return identifiableType.getIdentifierDescriptor();\n} catch (UnsupportedMappingException e) {\n    // mapping-level defect: entity requires an id but none could be built\n    throw new IllegalStateException(\"Broken id mapping on \" + identifiableType.getTypeName(), e);\n}","preventionTips":["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"],"tags":["hibernate","orm-mapping","missing-id","entity","sqm"],"backgroundTag":"entity-missing-primary-key","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}