hibernate/hibernate-orm · error · ConnectionProviderConfigurationException

Unable to locate JndiService to lookup Datasource

Error message

Unable to locate JndiService to lookup Datasource

What it means

configure found a JNDI datasource name (hibernate.connection.datasource as String) but no JndiService is available in the service registry to perform the lookup — typically JNDI not configured in SE environments.

Solutions

  1. Ensure JNDI is available in the environment or use a non-JNDI connection provider
  2. Configure the datasource via 'hibernate.connection.datasource' only where a JndiService exists
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java:101 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/55acbff79ad08355. Report an issue: GitHub.

Appendix: source

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

		else if ( unwrapType.isAssignableFrom( DataSource.class) ) {
			return unwrapType.cast( getDataSource() );
		}
		else {
			throw new UnknownUnwrapTypeException( unwrapType );
		}
	}

	@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) {

View on GitHub (pinned to fad1729dce)