hibernate/hibernate-orm · error · HibernateException
ServiceRegistry passed to MetadataBuilder cannot be null
Error message
ServiceRegistry passed to MetadataBuilder cannot be null
What it means
Null-argument guard in getStandardServiceRegistry: MetadataBuilder construction received a ServiceRegistry (from MetadataSources) that is null. Bootstrapping cannot proceed without a registry to source services from.
Solutions
- Pass a non-null StandardServiceRegistry to MetadataSources/MetadataBuilder, e.g. built via StandardServiceRegistryBuilder.
- Check bootstrap code order: build the ServiceRegistry before constructing Metadata.
- Verify dependency injection actually supplied the registry bean (no null injection).
Defensive patterns
Strategy: validation
When it happens
Trigger: The MetadataBuilder is used with a missing or unexpected ServiceRegistry implementation.
Common situations: Calling the bootstrap SPI directly with a null ServiceRegistry or a registry type Hibernate does not recognize.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/9a40b1a4b6116263.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java:122
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
/**
* @author Steve Ebersole
*/
public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeContributions {
private final MetadataSources sources;
private final BootstrapContextImpl bootstrapContext;
private final MetadataBuildingOptionsImpl options;
public MetadataBuilderImpl(MetadataSources sources) {
this( sources, getStandardServiceRegistry( sources.getServiceRegistry() ) );
}
public static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
if ( serviceRegistry == null ) {
throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
}
else if ( serviceRegistry instanceof StandardServiceRegistry standardServiceRegistry ) {
return standardServiceRegistry;
}
else if ( serviceRegistry instanceof BootstrapServiceRegistry bootstrapServiceRegistry ) {
BOOT_LOGGER.badServiceRegistry();
return new StandardServiceRegistryBuilder( bootstrapServiceRegistry ).build();
}
else {
throw new HibernateException(
String.format(
"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
serviceRegistry.getClass().getName()
)
);
}
}
View on GitHub (pinned to fad1729dce)