{"record":{"id":"4beda827540dd74e","repo":"hibernate/hibernate-orm","slug":"attribute-mapping-must-define-a-name-attribute-co","errorCode":null,"errorMessage":"Attribute mapping must define a name attribute: containingClassName=[%s], propertyName=[%s], role=[%s]","messagePattern":"Attribute mapping must define a name attribute: containingClassName=\\[(.+?)\\], propertyName=\\[(.+?)\\], role=\\[(.+?)\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java","lineNumber":2172,"sourceCode":"\tprivate Object typeInstance(String typeName, Class<?> typeJavaType) {\n\t\tif ( !metadataBuildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) {\n\t\t\treturn FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( typeJavaType );\n\t\t}\n\t\telse {\n\t\t\tfinal String beanName = typeName + \":\" + TypeDefinition.NAME_COUNTER.getAndIncrement();\n\t\t\treturn metadataBuildingContext.getBootstrapContext().getManagedBeanRegistry()\n\t\t\t\t\t.getBean( beanName, typeJavaType ).getBeanInstance();\n\t\t}\n\t}\n\n\tprivate void prepareValueTypeViaReflection(\n\t\t\tMappingDocument sourceDocument,\n\t\t\tValue value,\n\t\t\tString containingClassName,\n\t\t\tString propertyName,\n\t\t\tAttributeRole attributeRole) {\n\t\tif ( StringHelper.isEmpty( propertyName ) ) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\t\"Attribute mapping must define a name attribute:\"\n\t\t\t\t\t+ \" containingClassName=[%s], propertyName=[%s], role=[%s]\"\n\t\t\t\t\t\t\t.formatted( containingClassName, propertyName,\n\t\t\t\t\t\t\t\t\tattributeRole.getFullPath() ),\n\t\t\t\t\tsourceDocument.getOrigin()\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tvalue.setTypeUsingReflection( containingClassName, propertyName );\n\t\t}\n\t\tcatch (MappingException ome) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\t\"Error calling Value#setTypeUsingReflection:\"\n\t\t\t\t\t+ \" containingClassName=[%s], propertyName=[%s], role=[%s]\"\n\t\t\t\t\t\t\t.formatted( containingClassName, propertyName,\n\t\t\t\t\t\t\t\t\tattributeRole.getFullPath() ),\n\t\t\t\t\tome,","sourceCodeStart":2154,"sourceCodeEnd":2190,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L2154-L2190","documentation":"Hibernate determines many attribute types by reflecting on containingClassName.propertyName (value.setTypeUsingReflection). If the mapping element carries no usable name (StringHelper.isEmpty(propertyName) is true), there is nothing to resolve and the binder aborts before even attempting reflection. This is a structural mapping defect, not a classpath problem.","triggerScenarios":"A property mapping element in hbm.xml without a name= attribute where an inline type was also not supplied, forcing the reflection path; programmatically built attribute sources that omit the name.","commonSituations":"Hand-written hbm.xml with a missing name attribute; templates or code generators emitting empty property elements; accidental deletion of the name attribute during editing.","solutions":["Add the name attribute to the property element","Or supply an explicit type attribute so reflection is not required","Validate hbm.xml against the XSD in CI to catch name-less property elements early"],"exampleFix":"// before\n<property column='email' type='string'/>\n\n// after\n<property name='email' column='email' type='string'/>","handlingStrategy":"validation","validationCode":"// reject any value-mapping element that has neither name nor type\nString[] valued = {\"property\", \"many-to-one\", \"one-to-one\", \"component\", \"any\"};\nfor (String tag : valued) {\n    NodeList nodes = doc.getElementsByTagName(tag);\n    for (int i = 0; i < nodes.getLength(); i++) {\n        Element e = (Element) nodes.item(i);\n        boolean noName = e.getAttributeNode(\"name\") == null || e.getAttribute(\"name\").isBlank();\n        boolean noType = e.getAttributeNode(\"type\") == null;\n        if (noName && noType) {\n            throw new IllegalStateException(\"<\" + tag + \"> must define name or type\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (MappingException e) at bootstrap; the message prints containingClassName, propertyName, and the attribute role. Add the missing name= (or an explicit type=) to the element the role points at.","preventionTips":["Always set name= on property mappings","Run XSD validation on mapping files in CI","Generate hbm.xml from tooling rather than by hand"],"tags":["hibernate","hbm-mapping","property-mapping","missing-attribute","mappingexception"],"backgroundTag":"orm-mapping-missing-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}