{"record":{"id":"77e220fbe72f123f","repo":"hibernate/hibernate-orm","slug":"one-to-many-association-must-specify-the-reference","errorCode":null,"errorMessage":"one to many association must specify the referenced entity","messagePattern":"one to many association must specify the referenced entity","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java","lineNumber":155,"sourceCode":"\t@Override\n\tpublic boolean isSimpleValue() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean isAlternateUniqueKey() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean hasFormula() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean isValid(MappingContext mappingContext) throws MappingException {\n\t\tif ( referencedEntityName == null ) {\n\t\t\tthrow new MappingException( \"one to many association must specify the referenced entity\" );\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic String getReferencedEntityName() {\n\t\treturn referencedEntityName;\n\t}\n\n\t/**\n\t * Associated entity on the \"many\" side\n\t */\n\tpublic void setReferencedEntityName(String referencedEntityName) {\n\t\tthis.referencedEntityName = referencedEntityName == null ? null : referencedEntityName.intern();\n\t}\n\n\t@Override\n\tpublic void setTypeUsingReflection(String className, String propertyName) {\n\t}","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java#L137-L173","documentation":"OneToMany#isValid throws when a one-to-many association mapping carries no referenced entity name. The mapping element (hbm <one-to-many> without class, or a programmatic OneToMany never given its target) is incomplete, so Hibernate cannot bind the association.","triggerScenarios":"An hbm <one-to-many/> element without the class attribute; a programmatic mapping where setReferencedEntityName was never called; XML templating dropping the class attribute; mappings generated with unfilled placeholders.","commonSituations":"Hand-written hbm collection mappings; copy-paste omissions; dynamically assembled XML mapping files.","solutions":["Add class=\"com.acme.Item\" (or entity-name=\"...\") to the <one-to-many> element.","If using the programmatic API, call setReferencedEntityName with the mapped entity name.","Add a metadata-build test so incomplete collection mappings fail in CI instead of at boot."],"exampleFix":"<!-- before -->\n<set name=\"items\">\n    <key column=\"order_id\"/>\n    <one-to-many/>\n</set>\n\n<!-- after -->\n<set name=\"items\">\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    // stack trace shows the owning collection - complete its\n    // <one-to-many class=\"...\"> element\n    throw e;\n}","preventionTips":["Always fully specify association targets in hbm; validate files against the hbm XSD.","Prefer annotations where the compiler checks the target class reference.","Build Metadata for all mappings in CI so incomplete collections fail early."],"tags":["hibernate","orm","mapping","one-to-many","hbm","referenced-entity"],"backgroundTag":"missing-referenced-entity","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}