{"record":{"id":"5a6996d69971b73f","repo":"hibernate/hibernate-orm","slug":"unable-to-create-requested-service-servicebindi","errorCode":null,"errorMessage":"Unable to create requested service [${serviceBinding.getServiceRole().getName()}] due to: ${e.getMessage()}","messagePattern":"Unable to create requested service \\[(.+?)\\] due to: (.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java","lineNumber":273,"sourceCode":"\t\tif ( serviceInitiator == null ) {\n\t\t\t// this condition should never ever occur\n\t\t\tthrow new UnknownServiceException( serviceBinding.getServiceRole() );\n\t\t}\n\n\t\ttry {\n\t\t\tfinal R service = serviceBinding.getLifecycleOwner().initiateService( serviceInitiator );\n\t\t\t// IMPL NOTE: the register call here is important to avoid potential stack overflow issues\n\t\t\t//\t\t      from recursive calls through #configureService\n\t\t\tif ( service != null ) {\n\t\t\t\tregisterService( serviceBinding, service );\n\t\t\t}\n\t\t\treturn service;\n\t\t}\n\t\tcatch ( ServiceException e ) {\n\t\t\tthrow e;\n\t\t}\n\t\tcatch ( Exception e ) {\n\t\t\tthrow new ServiceException( \"Unable to create requested service [\"\n\t\t\t\t\t+ serviceBinding.getServiceRole().getName() + \"] due to: \" + e.getMessage(), e );\n\t\t}\n\t}\n\n\t@Override\n\tpublic <R extends Service> void injectDependencies(@Nonnull ServiceBinding<R> serviceBinding) {\n\t\tfinal R service = serviceBinding.getService();\n\t\tapplyInjections( service );\n\t\tif ( service instanceof ServiceRegistryAwareService serviceRegistryAwareService ) {\n\t\t\tserviceRegistryAwareService.injectServices( this );\n\t\t}\n\t}\n\n\tprivate <R extends Service> void applyInjections(@Nonnull R service) {\n\t\ttry {\n\t\t\tfor ( var method : service.getClass().getMethods() ) {\n\t\t\t\tfinal var injectService = method.getAnnotation( InjectService.class );\n\t\t\t\tif ( injectService != null ) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java#L255-L291","documentation":"When a service is first requested, Hibernate calls its ServiceInitiator via initiateService; if that call throws any non-ServiceException, it is wrapped in ServiceException with the message \"Unable to create requested service [<role>] due to: <cause message>\". The named service role plus the chained cause identify exactly which configuration failed during registry bootstrap.","triggerScenarios":"Dialect resolution failing (no hibernate.dialect and no resolvable JDBC metadata), connection provider initialization errors, JNDI lookup failures for datasources, malformed cfg.xml/properties, or a custom service initiator throwing an unexpected exception.","commonSituations":"Native bootstrap without a dialect and without an open JDBC connection to resolve it; typo'd hibernate.dialect class name; missing JNDI name in app-server tests; custom initiator NPEs on unexpected configuration values.","solutions":["Read the 'due to:' suffix and the caused-by stack — fix the underlying condition, not this wrapper","Set hibernate.dialect explicitly (or supply JDBC settings so it can be resolved) when bootstrapping without a live connection","Validate datasource/JNDI configuration before building the registry","In custom initiators, validate inputs and throw ServiceException yourself with a precise message"],"exampleFix":"# before\n# no dialect, no usable JDBC url at bootstrap\nhibernate.connection.url=jdbc:h2:mem:test\n\n# after\nhibernate.dialect=org.hibernate.dialect.H2Dialect\nhibernate.connection.url=jdbc:h2:mem:test","handlingStrategy":"try-catch","validationCode":"// fail fast on the most common root causes before building the registry\nif (!configSettings.containsKey(AvailableSettings.DIALECT)\n        && !configSettings.containsKey(AvailableSettings.URL)\n        && !configSettings.containsKey(AvailableSettings.DATASOURCE)) {\n    throw new IllegalStateException(\"cannot resolve dialect: set hibernate.dialect or JDBC settings\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory = new MetadataBuilderImpl(registry).build().buildSessionFactory();\n}\ncatch (ServiceException e) {\n    Throwable cause = e.getCause(); // the initiator that actually failed\n    throw new BootstrapException(\"Hibernate bootstrap failed: \" + e.getMessage(), cause);\n}","preventionTips":["Always set hibernate.dialect explicitly when bootstrapping without a live JDBC connection","Validate datasource/JNDI settings before registry construction","Log the full caused-by chain — the 'due to:' message points at the failing service"],"tags":["service-registry","bootstrap","configuration","dialect"],"backgroundTag":"service-initialization-failure","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}