{"record":{"id":"a441bfe8b269dfa7","repo":"hibernate/hibernate-orm","slug":"referenced-entity-referencedentityname-d","errorCode":null,"errorMessage":"Referenced entity '\" + referencedEntityName + \"' does not exist","messagePattern":"Referenced entity '\" \\+ referencedEntityName \\+ \"' does not exist","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java","lineNumber":84,"sourceCode":"\t * Creates a {@linkplain ForeignKey foreign key constraint} in the\n\t * case that the foreign key of this association does not reference\n\t * the primary key of the referenced table, but instead some other\n\t * unique key.\n\t * <p>\n\t * We depend here on having a property of the referenced entity\n\t * that does hold the referenced unique key. We might have created\n\t * a \"synthetic\" composite property for this purpose.\n\t */\n\tpublic void createPropertyRefConstraints(Map<String, PersistentClass> persistentClasses) {\n\t\tif ( referencedPropertyName != null ) {\n\t\t\t// Ensure properties are sorted before we create a foreign key\n\t\t\tsortProperties();\n\n\t\t\tfinal String referencedEntityName = getReferencedEntityName();\n\t\t\tfinal String referencedPropertyName = getReferencedPropertyName();\n\t\t\tfinal var referencedClass = persistentClasses.get( referencedEntityName );\n\t\t\tif ( referencedClass == null ) {\n\t\t\t\tthrow new MappingException( \"Referenced entity '\" + referencedEntityName + \"' does not exist\" );\n\n\t\t\t}\n\t\t\tfinal var property = referencedClass.getReferencedProperty( referencedPropertyName );\n\t\t\tif ( property==null ) {\n\t\t\t\tthrow new MappingException( \"Referenced entity '\" + referencedEntityName\n\t\t\t\t\t\t+ \"' has no property named '\" + referencedPropertyName + \"'\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Make sure synthetic properties are sorted\n\t\t\t\tif ( property.getValue() instanceof Component component ) {\n\t\t\t\t\tcomponent.sortProperties();\n\t\t\t\t}\n\t\t\t\t// todo : if \"none\" another option is to create the ForeignKey object still\tbut to set its #disableCreation flag\n\t\t\t\tif ( isConstrained() && !hasAuxiliaryColumnInPrimaryKey( referencedClass ) ) {\n\t\t\t\t\tfinal var foreignKey = getTable().createForeignKey(\n\t\t\t\t\t\t\tgetForeignKeyName(),\n\t\t\t\t\t\t\tgetConstraintColumns(),\n\t\t\t\t\t\t\tgetType().getAssociatedEntityName(),","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java#L66-L102","documentation":"ManyToOne#createPropertyRefConstraints resolves the target of a property-ref association (an association referencing a non-PK property) and throws when no mapped entity exists under the referenced entity name.","triggerScenarios":"An hbm <many-to-one property-ref=\"...\" class=\"WrongName\">; an entity was renamed or given an explicit entity-name while property-ref mappings kept the old name; the referenced entity was removed from the persistence unit; @Entity(name=...) changed after mappings referencing it were written.","commonSituations":"Renaming entities or introducing explicit entity names; cleaning up domain models while hbm files keep stale references.","solutions":["Set the association's target to the exact mapped entity name (fully-qualified class name or entity-name).","If the entity was renamed, update every property-ref association pointing at it.","Re-add the entity to the mapping set if it was removed by mistake."],"exampleFix":"<!-- before -->\n<many-to-one name=\"user\" class=\"com.acme.Usr\" property-ref=\"sso\"/>\n\n<!-- after -->\n<many-to-one name=\"user\" class=\"com.acme.User\" property-ref=\"sso\"/>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory = configuration.buildSessionFactory();\n} catch (MappingException e) {\n    // 'Referenced entity <name> does not exist' - check <name> against\n    // mapped entity names in this persistence unit\n    throw e;\n}","preventionTips":["Centralize entity-name constants when using entity-name based references.","Boot-test every property-ref association with a metadata build in CI.","Prefer plain FK-to-PK associations; use property-ref only when required and document each one."],"tags":["hibernate","orm","mapping","property-ref","many-to-one","referenced-entity"],"backgroundTag":"property-ref-target-missing","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}