hibernate/hibernate-orm · error · ServiceException

Unable to instantiate specified multi-tenant connection…

Error message

Unable to instantiate specified multi-tenant connection provider [{}]

What it means

Wraps reflective instantiation failure of the multi-tenant connection provider class configured via hibernate.multiTenancy.connection.provider. The cause carries the underlying construction exception.

Solutions

  1. Ensure the MultiTenantConnectionProvider class has an accessible constructor and required dependencies
  2. Fix the configured class name for the multi-tenant connection provider
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/MultiTenantConnectionProviderInitiator.java:72 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/8ab5a9b1e73c5eca. Report an issue: GitHub.

Appendix: source

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

		final Object configValue = configurationValues.get( MULTI_TENANT_CONNECTION_PROVIDER );
		if ( configValue == null ) {
			// if they also specified the data source *name*, then let's assume they want
			// DataSourceBasedMultiTenantConnectionProviderImpl
			final Object dataSourceConfigValue = configurationValues.get( JdbcSettings.DATASOURCE );
			return dataSourceConfigValue instanceof String
					? new DataSourceBasedMultiTenantConnectionProviderImpl<>()
					: null;
		}
		else if ( configValue instanceof MultiTenantConnectionProvider<?> multiTenantConnectionProvider ) {
			return multiTenantConnectionProvider;
		}
		else {
			final var providerClass = providerClass( registry, configValue );
			try {
				return providerClass.newInstance();
			}
			catch (Exception e) {
				throw new ServiceException( "Unable to instantiate specified multi-tenant connection provider [" + providerClass.getName() + "]", e );
			}
		}
	}

	private static Class<? extends MultiTenantConnectionProvider<?>> providerClass(
			ServiceRegistryImplementor registry, Object configValue) {
		if ( configValue instanceof Class<?> configType ) {
			if ( !MultiTenantConnectionProvider.class.isAssignableFrom( configType ) ) {
				throw new ConnectionProviderConfigurationException( "Class '" + configType.getName()
								+ "' does not implement 'MultiTenantConnectionProvider'" );
			}
			@SuppressWarnings("unchecked") // Safe, we just checked
			final var providerClass = (Class<? extends MultiTenantConnectionProvider<?>>) configType;
			return providerClass;
		}
		else {
			final String className = configValue.toString();
			final var classLoaderService = registry.requireService( ClassLoaderService.class );

View on GitHub (pinned to fad1729dce)