{"record":{"id":"4797f9a823c91ae8","repo":"hibernate/hibernate-orm","slug":"can-t-use-this-method-on-for-strategy-types-which","errorCode":null,"errorMessage":"Can't use this method on for strategy types which are embedded in the core library","messagePattern":"Can't use this method on for strategy types which are embedded in the core library","errorType":"exception","errorClass":"StrategySelectionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java","lineNumber":130,"sourceCode":"\t@Override\n\tpublic <T> T resolveStrategy(\n\t\t\tClass<T> strategy,\n\t\t\tObject strategyReference,\n\t\t\tT defaultValue,\n\t\t\tStrategyCreator<T> creator) {\n\t\treturn resolveStrategy(\n\t\t\t\tstrategy,\n\t\t\t\tstrategyReference,\n\t\t\t\t(Callable<T>) () -> defaultValue,\n\t\t\t\tcreator\n\t\t);\n\t}\n\n\t@Override\n\tpublic <T> Collection<Class<? extends T>> getRegisteredStrategyImplementors(Class<T> strategy) {\n\t\tfinal var lazyServiceResolver = lazyStrategyImplementorByStrategyMap.get( strategy );\n\t\tif ( lazyServiceResolver != null ) {\n\t\t\tthrow new StrategySelectionException( \"Can't use this method on for strategy types which are embedded in the core library\" );\n\t\t}\n\t\tfinal var registrations = namedStrategyImplementorByStrategyMap.get( strategy );\n\t\tif ( registrations == null ) {\n\t\t\treturn emptySet();\n\t\t}\n\t\telse {\n\t\t\tfinal Set<Class<? extends T>> implementors = new HashSet<>();\n\t\t\tfor ( var registration : registrations.values() ) {\n\t\t\t\tif ( !strategy.isAssignableFrom( registration ) ) {\n\t\t\t\t\tthrow new StrategySelectionException(\n\t\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\t\t\"Registered strategy [%s] is not a subtype of [%s]\",\n\t\t\t\t\t\t\t\t\tregistration.getName(),\n\t\t\t\t\t\t\t\t\tstrategy.getName()\n\t\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\timplementors.add( registration.asSubclass( strategy ) );","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java#L112-L148","documentation":"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.","triggerScenarios":"Calling strategySelector.getRegisteredStrategyImplementors(Dialect.class) or getRegisteredStrategyImplementors(JtaPlatform.class) - the two roles registered lazily by Hibernate core - instead of resolving an implementor by name.","commonSituations":"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.","solutions":["Resolve lazily registered strategies by name via selectStrategyImplementor(strategy, name) instead of enumerating","Maintain your own list of supported dialects/JTA platforms if you must display them","Restrict getRegisteredStrategyImplementors to your own custom strategy roles that are registered eagerly"],"exampleFix":"// before\nCollection<Class<? extends Dialect>> dialects =\n    strategySelector.getRegisteredStrategyImplementors(Dialect.class); // throws\n\n// after\nClass<? extends Dialect> d =\n    strategySelector.selectStrategyImplementor(Dialect.class, \"PostgreSQL\");","handlingStrategy":"validation","validationCode":"// Skip enumeration for lazily resolved core strategies\nstatic final Set<Class<?>> LAZY_STRATEGIES = Set.of(Dialect.class, JtaPlatform.class);\nif (LAZY_STRATEGIES.contains(strategy)) {\n    // resolve by name instead of enumerating\n    return List.of(strategySelector.selectStrategyImplementor(strategy, name));\n}","typeGuard":"// Java predicate narrowing the safe API per strategy type\nstatic boolean isEagerlyEnumerable(Class<?> strategy) {\n    return !(Dialect.class.equals(strategy) || JtaPlatform.class.equals(strategy));\n}","tryCatchPattern":"try {\n    return strategySelector.getRegisteredStrategyImplementors(strategy);\n} catch (StrategySelectionException e) {\n    if (e.getMessage().contains(\"embedded in the core library\")) {\n        return List.of(); // lazily resolved role: cannot be enumerated\n    }\n    throw e;\n}","preventionTips":["Never enumerate Dialect/JtaPlatform implementors through StrategySelector in Hibernate 6+","Resolve core strategies by name (selectStrategyImplementor) instead of listing","Maintain your own supported-dialect list for UIs and diagnostics"],"tags":["hibernate","strategy","dialect","internal-api","hibernate-6"],"backgroundTag":"unsupported-operation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}