{"record":{"id":"9a40b1a4b6116263","repo":"hibernate/hibernate-orm","slug":"serviceregistry-passed-to-metadatabuilder-cannot-b","errorCode":null,"errorMessage":"ServiceRegistry passed to MetadataBuilder cannot be null","messagePattern":"ServiceRegistry passed to MetadataBuilder cannot be null","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java","lineNumber":122,"sourceCode":"import static org.hibernate.internal.util.StringHelper.nullIfEmpty;\nimport static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;\n\n/**\n * @author Steve Ebersole\n */\npublic class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeContributions {\n\n\tprivate final MetadataSources sources;\n\tprivate final BootstrapContextImpl bootstrapContext;\n\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","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java#L104-L140","documentation":"Error \"ServiceRegistry passed to MetadataBuilder cannot be null\" 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":["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)."],"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"}