{"record":{"id":"73ec7f0372288b70","repo":"hibernate/hibernate-orm","slug":"could-not-resolve-serviceregistry","errorCode":null,"errorMessage":"Could not resolve ServiceRegistry","messagePattern":"Could not resolve ServiceRegistry","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/Property.java","lineNumber":472,"sourceCode":"\t\t}\n\t\telse {\n\t\t\treturn accessorName;\n\t\t}\n\t}\n\n\tprivate static boolean isMapEntity(Class<?> clazz) {\n\t\treturn clazz == null || Map.class.equals( clazz );\n\t}\n\n\tprivate ServiceRegistry resolveServiceRegistry() {\n\t\tif ( getPersistentClass() != null ) {\n\t\t\treturn getPersistentClass().getServiceRegistry();\n\t\t}\n\t\telse if ( getValue() != null ) {\n\t\t\treturn getValue().getServiceRegistry();\n\t\t}\n\t\telse {\n\t\t\tthrow new HibernateException( \"Could not resolve ServiceRegistry\" );\n\t\t}\n\t}\n\n\tpublic boolean isNaturalIdentifier() {\n\t\treturn naturalIdentifier;\n\t}\n\n\tpublic void setNaturalIdentifier(boolean naturalIdentifier) {\n\t\tthis.naturalIdentifier = naturalIdentifier;\n\t}\n\n\tpublic boolean isGeneric() {\n\t\treturn isGeneric;\n\t}\n\n\tpublic void setGeneric(boolean generic) {\n\t\tthis.isGeneric = generic;\n\t}","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/Property.java#L454-L490","documentation":"Property could not find a ServiceRegistry because it is bound to neither a PersistentClass nor a Value. resolveServiceRegistry() first tries the owning persistent class, then the value; with both absent the Property is an unattached stub, and any call that needs services (type resolution, cascade styles) fails with this HibernateException. It means the Property was used before being wired into a mapping.","triggerScenarios":"A directly constructed Property (new Property()) used for service-dependent calls before setValue() or setPersistentClass(); copying a Property between bindings without its value; utility code creating placeholder properties.","commonSituations":"Custom metamodel builders; test fixtures assembling mapping objects by hand; integrations that clone mapping fragments.","solutions":["Set a Value on the Property before any service-dependent call","Obtain Property instances from an already-built PersistentClass instead of constructing them","When cloning properties, clone the value graph as well"],"exampleFix":"// before\nProperty p = new Property();\np.getType(); // fails: no value and no persistent class\n\n// after\nProperty p = new Property();\np.setValue(new SimpleValue(metadata));\np.getType();","handlingStrategy":"validation","validationCode":"// construct-then-wire: always set a Value (or owning class) before service-dependent calls\nProperty p = new Property();\np.setValue(new SimpleValue(metadata));\n// only now call p.getType(), p.getCascadeStyle(), ...","typeGuard":"static boolean isAttachedToMapping(Property p) {\n    return p != null && (p.getValue() != null || p.getPersistentClass() != null);\n}","tryCatchPattern":null,"preventionTips":["Obtain Property instances from built PersistentClass objects rather than constructing them","When cloning mapping fragments, clone the Value graph in the same operation"],"tags":["hibernate","orm","internal-api","object-state","service-registry"],"backgroundTag":"invalid-object-state","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}