{"record":{"id":"39c1191b10504d4b","repo":"hibernate/hibernate-orm","slug":"detected-a-second-lazyserviceresolver-replacing-an","errorCode":null,"errorMessage":"Detected a second LazyServiceResolver replacing an existing LazyServiceResolver implementation for strategy {}","messagePattern":"Detected a second LazyServiceResolver replacing an existing LazyServiceResolver implementation for strategy (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java","lineNumber":208,"sourceCode":"\tprivate static <T> T create(Class<T> strategyClass) {\n\t\ttry {\n\t\t\treturn strategyClass.getDeclaredConstructor().newInstance();\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new StrategySelectionException(\n\t\t\t\t\tString.format( \"Could not instantiate named strategy class [%s]\", strategyClass.getName() ),\n\t\t\t\t\te\n\t\t\t);\n\t\t}\n\t}\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Lifecycle\n\n\tpublic <T> void registerStrategyLazily(Class<T> strategy, LazyServiceResolver<T> resolver) {\n\t\tfinal var previous = lazyStrategyImplementorByStrategyMap.put( strategy, resolver );\n\t\tif ( previous != null ) {\n\t\t\tthrow new HibernateException( \"Detected a second LazyServiceResolver replacing an existing LazyServiceResolver implementation for strategy \" + strategy.getName() );\n\t\t}\n\t}\n\n\tprivate <T> void contributeImplementation(Class<T> strategy, Class<? extends T> implementation, String... names) {\n\t\tfinal var namedStrategyImplementorMap =\n\t\t\t\tnamedStrategyImplementorByStrategyMap.computeIfAbsent( strategy, clazz -> new ConcurrentHashMap<>() );\n\t\tfor ( String name : names ) {\n\t\t\tfinal var old = namedStrategyImplementorMap.put( name, implementation );\n\t\t\tif ( BOOT_LOGGER.isTraceEnabled() ) {\n\t\t\t\tif ( old == null ) {\n\t\t\t\t\tBOOT_LOGGER.strategySelectorMapping(\n\t\t\t\t\t\t\tstrategy.getSimpleName(),\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\timplementation.getName()\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tBOOT_LOGGER.strategySelectorMappingReplacing(","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java#L190-L226","documentation":"Hibernate 6 registers exactly one LazyServiceResolver per lazily handled strategy role (Dialect and JtaPlatform via StrategySelectorBuilder). registerStrategyLazily() throws HibernateException when a second resolver arrives for a role that already has one, because two lazy resolvers cannot be merged and silently replacing the first would hide conflicting integrations.","triggerScenarios":"Two providers registering a lazy resolver for the same strategy class - in practice almost always Hibernate's own contributions arriving twice: hibernate-core classes embedded in a shaded/fat jar plus the real dependency on the classpath, or duplicate hibernate-core artifacts across classloaders.","commonSituations":"Uber-jars bundling hibernate-core classes; application servers with Hibernate present in both a server module and the deployment; mixed Hibernate versions across modules; a custom jar copying Hibernate's StrategySelectorBuilder contributions.","solutions":["Deduplicate hibernate-core on the classpath (dependency:tree, shading rules, server module lists)","Exclude embedded Hibernate classes from the fat jar or mark the dependency as provided","Align all modules on a single Hibernate version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Boot-time guard: exactly one hibernate-core on the classpath\nEnumeration<URL> urls = cl.getResources(\"org/hibernate/Version.class\");\nList<URL> found = Collections.list(urls);\nif (found.size() > 1) {\n    throw new IllegalStateException(\"Multiple hibernate-core copies detected: \" + found);\n}","typeGuard":null,"tryCatchPattern":"try {\n    strategySelector.registerStrategyLazily(Dialect.class, resolver);\n} catch (HibernateException e) {\n    if (e.getMessage().contains(\"second LazyServiceResolver\")) {\n        // duplicate Hibernate contributions: audit classpath for embedded/shaded copies\n        log.error(\"Duplicate Hibernate artifacts detected - deduplicate hibernate-core\", e);\n    }\n    throw e;\n}","preventionTips":["Never shade or embed hibernate-core classes in your application jar","Verify a single hibernate-core artifact with dependency:tree in CI","Align all modules on one Hibernate version to avoid partial duplicates"],"tags":["hibernate","strategy","duplicate-dependency","classpath","boot"],"backgroundTag":"duplicate-service-registration","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}