hibernate/hibernate-orm · error · ConnectionProviderConfigurationException

DataSource to use was not injected nor specified by…

Error message

DataSource to use was not injected nor specified by 'hibernate.connection.datasource'

What it means

configure's datasource setting was neither a DataSource instance nor a JNDI name string (e.g. a wrong type or blank value), so no datasource could be determined from hibernate.connection.datasource.

Solutions

  1. Set 'hibernate.connection.datasource' to the JNDI name of the DataSource
  2. Inject a DataSource into DataSourceConnectionProvider programmatically
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java:106 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/396d0677369350a5. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java:106

		}
	}

	@Override
	public void configure(@Nonnull Map<String, Object> configuration) {
		if ( dataSource == null ) {
			final Object dataSourceSetting = configuration.get( DATASOURCE );
			if ( dataSourceSetting instanceof DataSource instance ) {
				dataSource = instance;
			}
			else if ( dataSourceSetting instanceof String jndiName ) {
				dataSourceJndiName = jndiName;
				if ( jndiService == null ) {
					throw new ConnectionProviderConfigurationException( "Unable to locate JndiService to lookup Datasource" );
				}
				dataSource = (DataSource) jndiService.locate( jndiName );
			}
			else {
				throw new ConnectionProviderConfigurationException(
						"DataSource to use was not injected nor specified by '" + DATASOURCE + "'" );
			}
		}
		if ( dataSource == null ) {
			throw new ConnectionProviderConfigurationException( "Unable to determine appropriate DataSource to use" );
		}

		final Integer loginTimeout = getInteger( LOGIN_TIMEOUT, configuration );
		if ( loginTimeout != null ) {
			try {
				dataSource.setLoginTimeout( loginTimeout );
			}
			catch (SQLException e) {
				CONNECTION_INFO_LOGGER.couldNotSetLoginTimeout( e );
			}
		}

		if ( configuration.containsKey( JdbcSettings.AUTOCOMMIT ) ) {

View on GitHub (pinned to fad1729dce)