{"record":{"id":"33427644cc46286f","repo":"hibernate/hibernate-orm","slug":"expecting-component-for-id-mapping-with-no-id-attr","errorCode":null,"errorMessage":"Expecting Component for id mapping with no id-attribute","messagePattern":"Expecting Component for id mapping with no id-attribute","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java","lineNumber":519,"sourceCode":"\t\t\t\t\t\t(SingularPersistentAttribute<T, ?>)\n\t\t\t\t\t\t\t\tbuildAttribute( declaredIdentifierProperty, identifiableType,\n\t\t\t\t\t\t\t\t\t\tthis::buildIdAttribute );\n\t\t\t\tattributeContainer.getInFlightAccess().applyIdAttribute( idAttribute );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal var superclassIdentifier = getMappedSuperclassIdentifier( persistentClass );\n\t\t\t\tif ( superclassIdentifier != null && superclassIdentifier.isGeneric() ) {\n\t\t\t\t\t// If the superclass identifier is generic, we have to build the attribute to register the concrete type\n\t\t\t\t\tfinal var concreteIdentifier =\n\t\t\t\t\t\t\tbuildIdAttribute( identifiableType, persistentClass.getIdentifierProperty() );\n\t\t\t\t\tattributeContainer.getInFlightAccess().addConcreteGenericAttribute( concreteIdentifier );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// we have a non-aggregated composite-id\n\t\t\tif ( !( persistentClass.getIdentifier() instanceof Component compositeId ) ) {\n\t\t\t\tthrow new MappingException( \"Expecting Component for id mapping with no id-attribute\" );\n\t\t\t}\n\n\t\t\tapplyIdAttributes( persistentClass, identifiableType, compositeId );\n\t\t}\n\t}\n\n\tprivate <T> void applyIdAttributes(\n\t\t\tPersistentClass persistentClass,\n\t\t\tIdentifiableDomainType<T> identifiableType,\n\t\t\tComponent compositeId) {\n\t\tassert compositeId.isEmbedded();\n\t\t// Handle the actual id attributes\n\t\tfinal var identifierMapper = persistentClass.getIdentifierMapper();\n\t\tfinal var idClassType =\n\t\t\t\tidentifierMapper == null || identifierMapper.getComponentClassName() == null\n\t\t\t\t\t\t? null  // support for no @IdClass, especially for dynamic models\n\t\t\t\t\t\t: applyIdClassMetadata( (Component) persistentClass.getIdentifier() );\n\t\tfinal var id = identifierMapper == null ? compositeId : identifierMapper;","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java#L501-L537","documentation":"A org.hibernate.mapping.MappingException thrown by MetadataContext while populating the JPA metamodel for an entity that has no id attribute (persistentClass.getIdentifierProperty() == null). In that situation Hibernate expects a non-aggregated composite id, i.e. persistentClass.getIdentifier() must be a Component; when the identifier is some other kind of value (for example an <id> mapping without a name/property, producing a bare SimpleValue), the JPA metamodel step aborts with this error during EntityManagerFactory/SessionFactory creation.","triggerScenarios":"Legacy hbm.xml mappings with <id column=\"...\"> that declare no 'name' attribute (no id property) while JPA metamodel population is active; dynamic-map or map-mode entities whose composite id is not built as a Component; mapping combinations produced by hand-edited or generated XML where the identifier ends up as a simple value with no corresponding attribute.","commonSituations":"Maintaining old Hibernate 3/4-style hbm.xml mappings that predate property-based id declarations; running the JPA bootstrap (EntityManagerFactory) over mappings originally written for native SessionFactory usage; migration tooling that drops attributes while reshaping id mappings.","solutions":["Give the identifier a property: <id name=\"id\" column=\"ID\"> with a matching Java field, or map it as <composite-id name=\"...\" class=\"...\">","If the id genuinely has no attribute, declare it as a proper composite (Component) so the JPA metamodel can enumerate its attributes","Prefer JPA annotations (@Id/@EmbeddedId/@IdClass) for new mappings to avoid this legacy corner","Validate all hbm.xml id declarations before switching from native to JPA bootstrap"],"exampleFix":"<!-- before - id without a property: JPA metamodel fails -->\n<class name=\"User\" table=\"USERS\">\n    <id column=\"USER_ID\">\n        <generator class=\"assigned\"/>\n    </id>\n</class>\n\n<!-- after - id bound to an attribute -->\n<class name=\"User\" table=\"USERS\">\n    <id name=\"id\" column=\"USER_ID\">\n        <generator class=\"assigned\"/>\n    </id>\n</class>\npublic class User { private Long id; ... }","handlingStrategy":"validation","validationCode":"// Static check over hbm.xml before JPA bootstrap: every <id> must bind a property\nDocument doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(hbmFile);\nNodeList ids = doc.getElementsByTagName(\"id\");\nfor (int i = 0; i < ids.getLength(); i++) {\n    Element id = (Element) ids.item(i);\n    if ( !id.hasAttribute(\"name\") ) {\n        throw new IllegalStateException(\"<id> without 'name' in \" + hbmFile + \" breaks JPA metamodel building\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    EntityManagerFactory emf = Persistence.createEntityManagerFactory(\"pu\");\n}\ncatch ( org.hibernate.mapping.MappingException e ) {\n    if ( \"Expecting Component for id mapping with no id-attribute\".equals(e.getMessage()) ) {\n        throw new ConfigurationError(\"An <id>/<composite-id> mapping lacks a bound id attribute - add name/class\", e);\n    }\n    throw e;\n}","preventionTips":["Always bind identifiers to a property (name=) in XML or use @Id annotations","Lint legacy hbm.xml files before running them under the JPA (EntityManagerFactory) bootstrap","Prefer @EmbeddedId/@IdClass annotations for composite ids instead of hand-written XML"],"tags":["hibernate","jpa","composite-id","mapping","metamodel","hbm-xml"],"backgroundTag":"composite-id-mapping-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}