{"record":{"id":"55acbff79ad08355","repo":"hibernate/hibernate-orm","slug":"unable-to-locate-jndiservice-to-lookup-datasource","errorCode":null,"errorMessage":"Unable to locate JndiService to lookup Datasource","messagePattern":"Unable to locate JndiService to lookup Datasource","errorType":"exception","errorClass":"ConnectionProviderConfigurationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java","lineNumber":101,"sourceCode":"\t\telse if ( unwrapType.isAssignableFrom( DataSource.class) ) {\n\t\t\treturn unwrapType.cast( getDataSource() );\n\t\t}\n\t\telse {\n\t\t\tthrow new UnknownUnwrapTypeException( unwrapType );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void configure(@Nonnull Map<String, Object> configuration) {\n\t\tif ( dataSource == null ) {\n\t\t\tfinal Object dataSourceSetting = configuration.get( DATASOURCE );\n\t\t\tif ( dataSourceSetting instanceof DataSource instance ) {\n\t\t\t\tdataSource = instance;\n\t\t\t}\n\t\t\telse if ( dataSourceSetting instanceof String jndiName ) {\n\t\t\t\tdataSourceJndiName = jndiName;\n\t\t\t\tif ( jndiService == null ) {\n\t\t\t\t\tthrow new ConnectionProviderConfigurationException( \"Unable to locate JndiService to lookup Datasource\" );\n\t\t\t\t}\n\t\t\t\tdataSource = (DataSource) jndiService.locate( jndiName );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ConnectionProviderConfigurationException(\n\t\t\t\t\t\t\"DataSource to use was not injected nor specified by '\" + DATASOURCE + \"'\" );\n\t\t\t}\n\t\t}\n\t\tif ( dataSource == null ) {\n\t\t\tthrow new ConnectionProviderConfigurationException( \"Unable to determine appropriate DataSource to use\" );\n\t\t}\n\n\t\tfinal Integer loginTimeout = getInteger( LOGIN_TIMEOUT, configuration );\n\t\tif ( loginTimeout != null ) {\n\t\t\ttry {\n\t\t\t\tdataSource.setLoginTimeout( loginTimeout );\n\t\t\t}\n\t\t\tcatch (SQLException e) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java#L83-L119","documentation":"Error \"Unable to locate JndiService to lookup Datasource\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java:101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure JNDI is available in the environment or use a non-JNDI connection provider","Configure the datasource via 'hibernate.connection.datasource' only where a JndiService exists"],"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"}