hibernate/hibernate-orm · error · StrategySelectionException

Can't use this method on for strategy types which are embedd

Error message

Can't use this method on for strategy types which are embedded in the core library

What it means

Some core strategy types - notably Dialect and JtaPlatform, registered via registerStrategyLazily in StrategySelectorBuilder - are resolved through LazyServiceResolver in Hibernate 6 so dozens of implementation classes are not loaded at boot. getRegisteredStrategyImplementors() cannot enumerate lazily resolved strategies, so it throws StrategySelectionException stating the method cannot be used for core-embedded (lazily resolved) strategy types.

Source

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

	@Override
	public <T> T resolveStrategy(
			Class<T> strategy,
			Object strategyReference,
			T defaultValue,
			StrategyCreator<T> creator) {
		return resolveStrategy(
				strategy,
				strategyReference,
				(Callable<T>) () -> defaultValue,
				creator
		);
	}

	@Override
	public <T> Collection<Class<? extends T>> getRegisteredStrategyImplementors(Class<T> strategy) {
		final var lazyServiceResolver = lazyStrategyImplementorByStrategyMap.get( strategy );
		if ( lazyServiceResolver != null ) {
			throw new StrategySelectionException( "Can't use this method on for strategy types which are embedded in the core library" );
		}
		final var registrations = namedStrategyImplementorByStrategyMap.get( strategy );
		if ( registrations == null ) {
			return emptySet();
		}
		else {
			final Set<Class<? extends T>> implementors = new HashSet<>();
			for ( var registration : registrations.values() ) {
				if ( !strategy.isAssignableFrom( registration ) ) {
					throw new StrategySelectionException(
							String.format(
									"Registered strategy [%s] is not a subtype of [%s]",
									registration.getName(),
									strategy.getName()
							)
					);
				}
				implementors.add( registration.asSubclass( strategy ) );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Resolve lazily registered strategies by name via selectStrategyImplementor(strategy, name) instead of enumerating
  2. Maintain your own list of supported dialects/JTA platforms if you must display them
  3. Restrict getRegisteredStrategyImplementors to your own custom strategy roles that are registered eagerly

Example fix

// before
Collection<Class<? extends Dialect>> dialects =
    strategySelector.getRegisteredStrategyImplementors(Dialect.class); // throws

// after
Class<? extends Dialect> d =
    strategySelector.selectStrategyImplementor(Dialect.class, "PostgreSQL");
Defensive patterns

Strategy: validation

Validate before calling

// Skip enumeration for lazily resolved core strategies
static final Set<Class<?>> LAZY_STRATEGIES = Set.of(Dialect.class, JtaPlatform.class);
if (LAZY_STRATEGIES.contains(strategy)) {
    // resolve by name instead of enumerating
    return List.of(strategySelector.selectStrategyImplementor(strategy, name));
}

Type guard

// Java predicate narrowing the safe API per strategy type
static boolean isEagerlyEnumerable(Class<?> strategy) {
    return !(Dialect.class.equals(strategy) || JtaPlatform.class.equals(strategy));
}

Try / catch

try {
    return strategySelector.getRegisteredStrategyImplementors(strategy);
} catch (StrategySelectionException e) {
    if (e.getMessage().contains("embedded in the core library")) {
        return List.of(); // lazily resolved role: cannot be enumerated
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling strategySelector.getRegisteredStrategyImplementors(Dialect.class) or getRegisteredStrategyImplementors(JtaPlatform.class) - the two roles registered lazily by Hibernate core - instead of resolving an implementor by name.

Common situations: Tooling or integrations written against Hibernate 5 that enumerated registered dialects (e.g., for diagnostics or UI dropdowns); migration to Hibernate 6 without adjusting this call.

Related errors


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