{"record":{"id":"b48d0e461715632d","repo":"hibernate/hibernate-orm","slug":"referenced-entity-referencedentityname-h","errorCode":null,"errorMessage":"Referenced entity '\" + referencedEntityName + \"' has no property named '\" + referencedPropertyName + \"'","messagePattern":"Referenced entity '\" \\+ referencedEntityName \\+ \"' has no property named '\" \\+ referencedPropertyName \\+ \"'","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java","lineNumber":89,"sourceCode":"\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(),\n\t\t\t\t\t\t\tgetForeignKeyDefinition(),\n\t\t\t\t\t\t\tgetForeignKeyOptions(),\n\t\t\t\t\t\t\tnew ArrayList<>( property.getColumns() )\n\t\t\t\t\t);\n\t\t\t\t\tforeignKey.setReferencedTable( property.getValue().getTable() );","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java#L71-L107","documentation":"ManyToOne#createPropertyRefConstraints throws when the target entity exists but exposes no property under the referenced property name. The association points at a field the target mapping does not declare or does not expose as a persistent property.","triggerScenarios":"property-ref=\"ssoToken\" while the entity's persistent property is named sso; the referenced property was renamed or made @Transient; the property lives on a subclass or superclass not visible through the referenced binding; access-type changes hiding the field.","commonSituations":"Refactors renaming target properties; copy-paste of property-ref values; switching field/getter access so a property no longer appears in the mapping.","solutions":["Use the exact persistent property name - check the target entity's mapping, not just the Java field.","If the property was renamed, update the property-ref value everywhere it appears.","Ensure the referenced property is persistent (not @Transient) and unique - property-refs must target a unique column."],"exampleFix":"<!-- before -->\n<many-to-one name=\"user\" class=\"com.acme.User\" property-ref=\"ssoToken\"/>\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    // message pairs entity + property name - verify the property exists\n    // in the target mapping and is unique\n    throw e;\n}","preventionTips":["Prefer primary-key references instead of property-ref when possible.","When renaming properties, search all mappings for property-ref attributes.","Keep a unique constraint on every property-ref target so the implicit FK stays valid."],"tags":["hibernate","orm","mapping","property-ref","many-to-one","unique-key"],"backgroundTag":"property-ref-target-missing","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}