{"record":{"id":"39c8bd16579aa52c","repo":"hibernate/hibernate-orm","slug":"must-specify-an-identifier-type-s","errorCode":null,"errorMessage":"must specify an identifier type: %s","messagePattern":"must specify an identifier type: (.+?)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java","lineNumber":617,"sourceCode":"\tprivate void bindSimpleEntityIdentifier(\n\t\t\tMappingDocument sourceDocument,\n\t\t\tfinal EntityHierarchySource hierarchySource,\n\t\t\tRootClass rootEntityDescriptor) {\n\t\tfinal var idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource();\n\n\t\tfinal var idValue = new BasicValue( sourceDocument, rootEntityDescriptor.getTable() );\n\t\trootEntityDescriptor.setIdentifier( idValue );\n\n\t\tbindSimpleValueType(\n\t\t\t\tsourceDocument,\n\t\t\t\tidSource.getIdentifierAttributeSource().getTypeInformation(),\n\t\t\t\tidValue\n\t\t);\n\n\t\tfinal String propertyName = idSource.getIdentifierAttributeSource().getName();\n\t\tif ( propertyName == null || !rootEntityDescriptor.hasPojoRepresentation() ) {\n\t\t\tif ( !idValue.isTypeSpecified() ) {\n\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\"must specify an identifier type: \" + rootEntityDescriptor.getEntityName(),\n\t\t\t\t\t\tsourceDocument.getOrigin()\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tidValue.setTypeUsingReflection( rootEntityDescriptor.getClassName(), propertyName );\n\t\t}\n\n\t\tfinal var identifierAttributeSource =\n\t\t\t\t(RelationalValueSourceContainer)\n\t\t\t\t\t\tidSource.getIdentifierAttributeSource();\n\t\trelationalObjectBinder.bindColumnsAndFormulas(\n\t\t\t\tsourceDocument,\n\t\t\t\tidentifierAttributeSource.getRelationalValueSources(),\n\t\t\t\tidValue,\n\t\t\t\tfalse,\n\t\t\t\tcontext -> {","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L599-L635","documentation":"Hibernate binds an <id> element in hbm.xml into a BasicValue and must end up with a concrete type. The type comes either from an explicit type attribute or from reflecting on the mapped class property named by name=. When the id has no explicit type and reflection is impossible (name missing, or the entity has no POJO representation such as dynamic-map entity-name mappings), binding aborts with this MappingException.","triggerScenarios":"<class entity-name='...' ...> (non-POJO / dynamic-map entity) with an <id> lacking a type attribute; an <id> element with no name attribute and no type; a template-generated mapping where type='long' was dropped.","commonSituations":"Dynamic-model entities (entity-name only, no class) where reflection cannot supply the type; hand-written or generator-produced hbm.xml files; migrations where the explicit type attribute got lost.","solutions":["Add an explicit type attribute to the <id> element, e.g. <id name='id' type='long'>","If the entity is a normal POJO, give <id> a name attribute matching an actual field/getter so Hibernate can resolve the type by reflection","For dynamic-map entities (entity-name without class), an explicit type on <id> is mandatory - add it"],"exampleFix":"// before\n<class entity-name='User' table='users'>\n    <id name='id'>\n        <generator class='native'/>\n    </id>\n</class>\n\n// after\n<class entity-name='User' table='users'>\n    <id name='id' type='long'>\n        <generator class='native'/>\n    </id>\n</class>","handlingStrategy":"validation","validationCode":"// before build: scan every <class> that has entity-name but no class, and every <id>\nNodeList ids = doc.getElementsByTagName(\"id\");\nfor (int i = 0; i < ids.getLength(); i++) {\n    Element id = (Element) ids.item(i);\n    boolean hasType = id.getAttributeNode(\"type\") != null;\n    boolean hasName = id.getAttributeNode(\"name\") != null;\n    Element owner = (Element) id.getParentNode();\n    boolean isPojo = owner.getAttributeNode(\"class\") != null;\n    if (!hasType && (!hasName || !isPojo)) {\n        throw new IllegalStateException(\"<id> needs an explicit type: \" + owner.getAttribute(\"entity-name\"));\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (MappingException e) during bootstrap; the message names the entity whose id lacks a type. Add type= to that entity's <id> and rebuild.","preventionTips":["Always give <id> an explicit type attribute","For dynamic-map entities treat type= on <id> as mandatory","Generate mappings from annotated classes rather than hand-writing them where possible"],"tags":["hibernate","hbm-mapping","identifier","dynamic-model","mappingexception"],"backgroundTag":"orm-mapping-missing-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}