{"record":{"id":"35e2eeb10be4aff4","repo":"hibernate/hibernate-orm","slug":"unknown-service-requested-servicerole-getname-35e2ee","errorCode":null,"errorMessage":"Unknown service requested [${serviceRole.getName()}]","messagePattern":"Unknown service requested \\[(.+?)\\]","errorType":"exception","errorClass":"UnknownServiceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java","lineNumber":209,"sourceCode":"\t\t\treturn parent.getService( serviceRole );\n\t\t}\n\t\t// TODO: should an exception be thrown if active == false???\n\t\tR service = serviceRole.cast( initializedServiceByRole.get( serviceRole ) );\n\t\tif ( service != null ) {\n\t\t\treturn service;\n\t\t}\n\n\t\t//Any service initialization needs synchronization\n\t\tsynchronized ( this ) {\n\t\t\t// Check again after having acquired the lock:\n\t\t\tservice = serviceRole.cast( initializedServiceByRole.get( serviceRole ) );\n\t\t\tif ( service != null ) {\n\t\t\t\treturn service;\n\t\t\t}\n\n\t\t\tfinal ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole );\n\t\t\tif ( serviceBinding == null ) {\n\t\t\t\tthrow new UnknownServiceException( serviceRole );\n\t\t\t}\n\t\t\tservice = serviceBinding.getService();\n\t\t\tif ( service == null ) {\n\t\t\t\tservice = initializeService( serviceBinding );\n\t\t\t}\n\t\t\tif ( service != null ) {\n\t\t\t\t// add the service only after it is completely initialized\n\t\t\t\tinitializedServiceByRole.put( serviceRole, service );\n\t\t\t}\n\t\t\treturn service;\n\t\t}\n\t}\n\n\tprotected <R extends Service> void registerService(@Nonnull ServiceBinding<R> serviceBinding, R service) {\n\t\tserviceBinding.setService( service );\n\t\tsynchronized ( serviceBindingList ) {\n\t\t\tserviceBindingList.add( serviceBinding );\n\t\t}","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java#L191-L227","documentation":"Inside getService(role), after taking the init lock, Hibernate looks up the ServiceBinding for the role; if no initiator or explicit registration ever created a binding for it, UnknownServiceException(\"Unknown service requested [...]\") is thrown. This is the runtime twin of the requireService path: the role is genuinely unknown to this registry (and not reachable through parent crawling).","triggerScenarios":"Requesting a service role with no registered binding; roles removed, renamed, or merged between Hibernate versions (notably 5.x to 6.x); a registry that was already destroyed; custom integrations assuming an internal service still exists.","commonSituations":"Upgrading Hibernate where internal service classes moved packages or were replaced; third-party dialects or integrations looking up version-specific services; services registered on a sibling registry rather than the requested one.","solutions":["Verify the role is registered: add a StandardServiceInitiator or ServiceContributor for it, or builder.addService(role, instance)","Check the Hibernate version's service list — the role may have been renamed/merged in the upgrade","Request from the correct registry in the hierarchy rather than an arbitrary one","Guard optional lookups with getService(role) == null instead of requireService"],"exampleFix":"// before\nfinal ConnectionProvider cp = registryService.getService(ConnectionProvider.class); // ok\nfinal MyService s = registryService.requireService(MyService.class); // UnknownServiceException\n\n// after\n// register the custom role before first use\npublic class MyServiceInitiator implements StandardServiceInitiator<MyService> {\n    public Class<MyService> getServiceInitiated() { return MyService.class; }\n    public MyService initiateService(ConfigurationValues configurationValues, ServiceRegistryImplementor registry) {\n        return new MyServiceImpl();\n    }\n}\n// + META-INF/services/org.hibernate.servicecontributor listing the contributor","handlingStrategy":"validation","validationCode":"MyService service = registry.getService(MyService.class);\nif (service == null) {\n    service = new MyServiceDefault();\n    // or: ((StandardServiceRegistryBuilder) builder).addService(MyService.class, service);\n}","typeGuard":"boolean isRoleBound(StandardServiceRegistry registry, Class<? extends Service> role) {\n    return registry.getService(role) != null; // null == unknown/unbound\n}","tryCatchPattern":"try {\n    return registry.requireService(role);\n}\ncatch (UnknownServiceException e) {\n    // role never registered here; register or degrade gracefully\n    LOG.warn(\"unknown service {} — not registered\", role.getName());\n    return null;\n}","preventionTips":["Register every custom role before first lookup via initiator or addService","After a Hibernate upgrade, re-verify lookups of internal services (roles move/merge)","Don't query registries after close(); stopped registries lose bindings"],"tags":["service-registry","bootstrap","version-upgrade"],"backgroundTag":"unknown-service-role","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}