hibernate/hibernate-orm · error · StrategySelectionException

Could not instantiate named strategy class [%s]

Error message

Could not instantiate named strategy class [%s]

What it means

When a strategy reference is non-null and not already an instance of the strategy, resolveStrategy resolves the implementation class (from the reference or selectStrategyImplementor) and hands it to the caller-supplied StrategyCreator; any exception from creator.create() is wrapped as StrategySelectionException 'Could not instantiate named strategy class [%s]'. The named class resolved fine - creating the instance failed.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java:181

				return defaultResolver.call();
			}
			catch (Exception e) {
				throw new StrategySelectionException( "Default resolver threw exception", e );
			}
		}
		else if ( strategy.isInstance( strategyReference ) ) {
			return strategy.cast( strategyReference );
		}
		else {
			final var implementationClass =
					strategyReference instanceof Class
							? (Class<? extends T>) strategyReference
							: selectStrategyImplementor( strategy, strategyReference.toString() );
			try {
				return creator.create( implementationClass );
			}
			catch (Exception e) {
				throw new StrategySelectionException(
						String.format( "Could not instantiate named strategy class [%s]",
								implementationClass.getName() ),
						e
				);
			}
		}
	}

	private static <T> T create(Class<T> strategyClass) {
		try {
			return strategyClass.getDeclaredConstructor().newInstance();
		}
		catch (Exception e) {
			throw new StrategySelectionException(
					String.format( "Could not instantiate named strategy class [%s]", strategyClass.getName() ),
					e
			);
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the strategy class has a usable public no-arg constructor
  2. Read the wrapped cause (getCause()) - it carries the actual construction failure; fix that underlying problem
  3. If the class needs arguments, instantiate it yourself and pass the instance (many settings accept an instance as well as a class/name)
  4. Supply a custom StrategyCreator that constructs the object with the arguments it needs
Defensive patterns

Strategy: validation

Validate before calling

// Verify a public no-arg constructor exists before accepting a strategy class
Constructor<?> c = implClass.getDeclaredConstructor();
if (!Modifier.isPublic(c.getModifiers()) || !Modifier.isPublic(implClass.getModifiers())) {
    throw new IllegalStateException(
        implClass.getName() + " needs a public no-arg constructor for Hibernate instantiation");
}

Try / catch

try {
    return creator.create(implementationClass);
} catch (StrategySelectionException e) {
    // getCause() carries the constructor/static-init failure - fix that, not this wrapper
    throw new ConfigurationException("Cannot create " + implementationClass.getName(), e.getCause());
}

Prevention

When it happens

Trigger: A strategy setting naming a class whose instantiation throws: a missing or inaccessible constructor, a constructor that fails (missing configuration, NPE), or a static initializer error - for custom dialects, ConnectionProviders, RegionFactories, JTA platforms, etc.

Common situations: Custom strategy classes without usable constructors; constructors reading configuration that is absent at creation time; classes whose static initialization touches unavailable resources; constructor injection designed for frameworks, not for reflective instantiation by Hibernate.

Related errors


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