hibernate/hibernate-orm · error · HibernateException
Could not resolve ServiceRegistry
Error message
Could not resolve ServiceRegistry
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/mapping/Property.java:472
}
else {
return accessorName;
}
}
private static boolean isMapEntity(Class<?> clazz) {
return clazz == null || Map.class.equals( clazz );
}
private ServiceRegistry resolveServiceRegistry() {
if ( getPersistentClass() != null ) {
return getPersistentClass().getServiceRegistry();
}
else if ( getValue() != null ) {
return getValue().getServiceRegistry();
}
else {
throw new HibernateException( "Could not resolve ServiceRegistry" );
}
}
public boolean isNaturalIdentifier() {
return naturalIdentifier;
}
public void setNaturalIdentifier(boolean naturalIdentifier) {
this.naturalIdentifier = naturalIdentifier;
}
public boolean isGeneric() {
return isGeneric;
}
public void setGeneric(boolean generic) {
this.isGeneric = generic;
}View on GitHub (pinned to fad1729dce)
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
Example fix
// before Property p = new Property(); p.getType(); // fails: no value and no persistent class // after Property p = new Property(); p.setValue(new SimpleValue(metadata)); p.getType();
Defensive patterns
Strategy: validation
Validate before calling
// construct-then-wire: always set a Value (or owning class) before service-dependent calls Property p = new Property(); p.setValue(new SimpleValue(metadata)); // only now call p.getType(), p.getCascadeStyle(), ...
Type guard
static boolean isAttachedToMapping(Property p) {
return p != null && (p.getValue() != null || p.getPersistentClass() != null);
} Prevention
- Obtain Property instances from built PersistentClass objects rather than constructing them
- When cloning mapping fragments, clone the Value graph in the same operation
When it happens
Trigger: 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.
Common situations: Custom metamodel builders; test fixtures assembling mapping objects by hand; integrations that clone mapping fragments.
Related errors
- Bootstrap registry should only contain provided services
- Can't reactivate an active registry
- Property not among declared properties: " + property.getName
- Could not initialize custom PersisterClassResolver impl [%s]
- Could not find table group for: %s
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/73ec7f0372288b70.
Report an issue: GitHub.