hibernate/hibernate-orm · error · HibernateException
Unexpected type of ServiceRegistry [%s] encountered in attem
Error message
Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder
What it means
Error "Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java:132
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()
)
);
}
}
public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {
this.sources = sources;
this.options = new MetadataBuildingOptionsImpl( serviceRegistry );
this.bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );
//this is needed only for implementing deprecated method
options.setBootstrapContext( bootstrapContext );
for ( MetadataSourcesContributor contributor :
sources.getServiceRegistry()
.requireService( ClassLoaderService.class )View on GitHub (pinned to fad1729dce)
Solutions
- Supply a StandardServiceRegistry (the bootstrap registry type), not an arbitrary ServiceRegistry implementation, when building Metadata.
- Build the registry via StandardServiceRegistryBuilder to get the correct type.
- Avoid passing the SessionFactory-level registry where the bootstrap registry is required.
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/4ba52afe87010cea.
Report an issue: GitHub.