{"record":{"id":"b5700150b91986b1","repo":"hibernate/hibernate-orm","slug":"no-serviceregistry-was-passed-to-configuration-bui","errorCode":null,"errorMessage":"No ServiceRegistry was passed to Configuration#buildSessionFactory and could not determine how to locate BootstrapServiceRegistry from Configuration instantiation","messagePattern":"No ServiceRegistry was passed to Configuration#buildSessionFactory and could not determine how to locate BootstrapServiceRegistry from Configuration instantiation","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java","lineNumber":224,"sourceCode":"\t * Create a new instance, using the given {@link MetadataSources}, and a\n\t * {@link BootstrapServiceRegistry} obtained from the {@link MetadataSources}.\n\t */\n\tpublic Configuration(MetadataSources metadataSources) {\n\t\tthis.metadataSources = metadataSources;\n\t\tbootstrapServiceRegistry = getBootstrapRegistry( metadataSources.getServiceRegistry() );\n\t\tstandardServiceRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );\n\t\tproperties.putAll( standardServiceRegistryBuilder.getSettings() );\n\t}\n\n\tprivate static BootstrapServiceRegistry getBootstrapRegistry(ServiceRegistry serviceRegistry) {\n\t\tif ( serviceRegistry instanceof BootstrapServiceRegistry bootstrapServiceRegistry ) {\n\t\t\treturn bootstrapServiceRegistry;\n\t\t}\n\t\telse if ( serviceRegistry instanceof StandardServiceRegistry ssr ) {\n\t\t\treturn (BootstrapServiceRegistry) ssr.getParentServiceRegistry();\n\t\t}\n\n\t\tthrow new HibernateException(\n\t\t\t\t\"No ServiceRegistry was passed to Configuration#buildSessionFactory \" +\n\t\t\t\t\t\t\"and could not determine how to locate BootstrapServiceRegistry \" +\n\t\t\t\t\t\t\"from Configuration instantiation\"\n\t\t);\n\t}\n\n\n\t// properties/settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\t/**\n\t * Get all properties\n\t *\n\t * @return all properties\n\t */\n\tpublic Properties getProperties() {\n\t\treturn properties;\n\t}\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java#L206-L242","documentation":"When Configuration#buildSessionFactory is used, Hibernate needs a BootstrapServiceRegistry as the anchor. It accepts one directly or unwraps it from a StandardServiceRegistry's parent chain; if the supplied ServiceRegistry is any other implementation, getBootstrapRegistry throws this HibernateException. The registry passed in cannot be traced back to a bootstrap registry, so factory construction is refused.","triggerScenarios":"Calling cfg.buildSessionFactory(customRegistry) where customRegistry is a wrapper or non-standard ServiceRegistry implementation; passing a framework-produced registry that is neither a BootstrapServiceRegistry nor a StandardServiceRegistry; bootstrap glue that rebuilds Configurations around existing registries.","commonSituations":"Custom or wrapped registries in framework integration code; legacy Configuration-based bootstrap mixed with new-style registry code; partial migration to StandardServiceRegistryBuilder.","solutions":["Pass a StandardServiceRegistry built via new StandardServiceRegistryBuilder().configure().build()","Or pass the BootstrapServiceRegistry itself when that is what you hold","Do not implement or wrap ServiceRegistry yourself; compose via StandardServiceRegistryBuilder instead","Prefer the modern bootstrap: new MetadataSources(ssr)...buildMetadata().buildSessionFactory()"],"exampleFix":"// before\nConfiguration cfg = new Configuration();\nServiceRegistry myRegistry = customWrapper(); // not a StandardServiceRegistry -> throws\nSessionFactory sf = cfg.buildSessionFactory(myRegistry);\n\n// after\nStandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure().build();\nSessionFactory sf = new MetadataSources(ssr).addAnnotatedClass(Item.class)\n        .buildMetadata().buildSessionFactory();","handlingStrategy":"validation","validationCode":"if (!(registry instanceof StandardServiceRegistry)\n        && !(registry instanceof BootstrapServiceRegistry)) {\n    throw new IllegalArgumentException(\n            \"Pass a StandardServiceRegistry or BootstrapServiceRegistry to buildSessionFactory\");\n}\nreturn cfg.buildSessionFactory(registry);","typeGuard":"static boolean isRegistryHibernateAccepts(ServiceRegistry registry) {\n    return registry instanceof StandardServiceRegistry\n            || registry instanceof BootstrapServiceRegistry;\n}","tryCatchPattern":null,"preventionTips":["Use StandardServiceRegistryBuilder as the single registry entry point","Never wrap or reimplement ServiceRegistry interfaces","Keep one registry per application lifecycle and close it after the SessionFactory"],"tags":["hibernate","bootstrap","service-registry","configuration"],"backgroundTag":"service-registry-resolution-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}