hibernate/hibernate-orm · error · HibernateException
ServiceRegistry passed to MetadataBuilder cannot be null
Error message
ServiceRegistry passed to MetadataBuilder cannot be null
What it means
Error "ServiceRegistry passed to MetadataBuilder cannot be null" thrown in hibernate/hibernate-orm.
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)
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).
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.