{"record":{"id":"4ba52afe87010cea","repo":"hibernate/hibernate-orm","slug":"unexpected-type-of-serviceregistry-s-encountere","errorCode":null,"errorMessage":"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder","messagePattern":"Unexpected type of ServiceRegistry \\[(.+?)\\] encountered in attempt to build MetadataBuilder","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java","lineNumber":132,"sourceCode":"\tprivate final MetadataBuildingOptionsImpl options;\n\n\tpublic MetadataBuilderImpl(MetadataSources sources) {\n\t\tthis( sources, getStandardServiceRegistry( sources.getServiceRegistry() ) );\n\t}\n\n\tpublic static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {\n\t\tif ( serviceRegistry == null ) {\n\t\t\tthrow new HibernateException( \"ServiceRegistry passed to MetadataBuilder cannot be null\" );\n\t\t}\n\t\telse if ( serviceRegistry instanceof StandardServiceRegistry standardServiceRegistry ) {\n\t\t\treturn standardServiceRegistry;\n\t\t}\n\t\telse if ( serviceRegistry instanceof BootstrapServiceRegistry bootstrapServiceRegistry ) {\n\t\t\tBOOT_LOGGER.badServiceRegistry();\n\t\t\treturn new StandardServiceRegistryBuilder( bootstrapServiceRegistry ).build();\n\t\t}\n\t\telse {\n\t\t\tthrow new HibernateException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder\",\n\t\t\t\t\t\t\tserviceRegistry.getClass().getName()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {\n\t\tthis.sources = sources;\n\t\tthis.options = new MetadataBuildingOptionsImpl( serviceRegistry );\n\t\tthis.bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );\n\t\t//this is needed only for implementing deprecated method\n\t\toptions.setBootstrapContext( bootstrapContext );\n\n\t\tfor ( MetadataSourcesContributor contributor :\n\t\t\t\tsources.getServiceRegistry()\n\t\t\t\t\t\t.requireService( ClassLoaderService.class )","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java#L114-L150","documentation":"Error \"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The MetadataBuilder is used with a missing or unexpected ServiceRegistry implementation.","commonSituations":"Calling the bootstrap SPI directly with a null ServiceRegistry or a registry type Hibernate does not recognize.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}