{"record":{"id":"396d0677369350a5","repo":"hibernate/hibernate-orm","slug":"datasource-to-use-was-not-injected-nor-specified-b","errorCode":null,"errorMessage":"DataSource to use was not injected nor specified by 'hibernate.connection.datasource'","messagePattern":"DataSource to use was not injected nor specified by 'hibernate\\.connection\\.datasource'","errorType":"exception","errorClass":"ConnectionProviderConfigurationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java","lineNumber":106,"sourceCode":"\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) {\n\t\t\t\tCONNECTION_INFO_LOGGER.couldNotSetLoginTimeout( e );\n\t\t\t}\n\t\t}\n\n\t\tif ( configuration.containsKey( JdbcSettings.AUTOCOMMIT ) ) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java#L88-L124","documentation":"Error \"DataSource to use was not injected nor specified by 'hibernate.connection.datasource'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java:106 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set 'hibernate.connection.datasource' to the JNDI name of the DataSource","Inject a DataSource into DataSourceConnectionProvider programmatically"],"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"}