{"record":{"id":"4ff961d1087b5da4","repo":"hibernate/hibernate-orm","slug":"an-association-from-the-table-gettable-getn","errorCode":null,"errorMessage":"An association from the table '\" + getTable().getName() + \"' does not specify the referenced entity","messagePattern":"An association from the table '\" \\+ getTable\\(\\)\\.getName\\(\\) \\+ \"' does not specify the referenced entity","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java","lineNumber":192,"sourceCode":"\t}\n\n\tpublic String toString() {\n\t\tif ( !isReferenceToPrimaryKey() ) {\n\t\t\treturn getClass().getSimpleName()\n\t\t\t\t\t+ '(' + getTable().getName() + getColumns()\n\t\t\t\t\t+ \" ref-columns:\" + '(' + getReferencedColumns() + \") as \" + getName() + \")\";\n\t\t}\n\t\telse {\n\t\t\treturn super.toString();\n\t\t}\n\n\t}\n\n\t@Internal\n\tpublic PersistentClass resolveReferencedClass(Metadata metadata) {\n\t\tfinal String referencedEntityName = getReferencedEntityName();\n\t\tif ( referencedEntityName == null ) {\n\t\t\tthrow new MappingException( \"An association from the table '\" + getTable().getName() +\n\t\t\t\t\t\"' does not specify the referenced entity\" );\n\t\t}\n\n\t\tfinal var referencedEntity = metadata.getEntityBinding( referencedEntityName );\n\t\tif ( referencedEntity == null ) {\n\t\t\tthrow new MappingException( \"An association from the table '\" + getTable().getName() +\n\t\t\t\t\t\"' refers to an unmapped class '\" + referencedEntityName + \"'\" );\n\t\t}\n\n\t\treturn referencedEntity;\n\t}\n}\n","sourceCodeStart":174,"sourceCodeEnd":205,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java#L174-L205","documentation":"ForeignKey#resolveReferencedClass throws when a mapped association's foreign key carries no referenced entity name at all. Hibernate needs the target entity to resolve the FK, so a key or association that never had its entity set is an incomplete mapping - typically a truncated hbm fragment.","triggerScenarios":"An hbm <one-to-many> element without its class attribute inside a bag or set; a programmatic mapping where setReferencedEntityName was never called; hand-edited hbm where the class attribute was deleted; mapping fragments loaded from templated files with placeholders unfilled.","commonSituations":"Hand-written or templated hbm.xml files; copy-paste mapping templates; XML processed by build tooling that strips attributes; migrations between annotation and hbm styles.","solutions":["Add the missing target: <one-to-many class=\"com.acme.Item\"/> or set the referenced entity name programmatically.","Validate that every hbm file loads and every association names its target entity.","Prefer annotation or programmatic mappings where the target entity is checked at compile time."],"exampleFix":"<!-- before -->\n<set name=\"items\" table=\"item\">\n    <key column=\"order_id\"/>\n    <one-to-many/>\n</set>\n\n<!-- after -->\n<set name=\"items\" table=\"item\">\n    <key column=\"order_id\"/>\n    <one-to-many class=\"com.acme.Item\"/>\n</set>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory = configuration.buildSessionFactory();\n} catch (MappingException e) {\n    // message includes the owning table - search mappings for associations\n    // on that table that lack a class / entity-name\n    throw e;\n}","preventionTips":["Never leave <one-to-many> or <many-to-many> elements without class or entity-name in hbm files.","Validate hbm files against the Hibernate mapping XSD so structurally incomplete elements are rejected early.","Add a startup or CI check that parses every hbm file and builds Metadata."],"tags":["hibernate","orm","mapping","hbm","referenced-entity","association"],"backgroundTag":"missing-referenced-entity","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}