{"record":{"id":"ce3359be794d8453","repo":"hibernate/hibernate-orm","slug":"default-resolver-threw-exception","errorCode":null,"errorMessage":"Default resolver threw exception","messagePattern":"Default resolver threw exception","errorType":"exception","errorClass":"StrategySelectionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java","lineNumber":166,"sourceCode":"\t\t\t\timplementors.add( registration.asSubclass( strategy ) );\n\t\t\t}\n\t\t\treturn implementors;\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\t@Override\n\tpublic <T> T resolveStrategy(\n\t\t\tClass<T> strategy,\n\t\t\tObject strategyReference,\n\t\t\tCallable<T> defaultResolver,\n\t\t\tStrategyCreator<T> creator) {\n\t\tif ( strategyReference == null ) {\n\t\t\ttry {\n\t\t\t\treturn defaultResolver.call();\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new StrategySelectionException( \"Default resolver threw exception\", e );\n\t\t\t}\n\t\t}\n\t\telse if ( strategy.isInstance( strategyReference ) ) {\n\t\t\treturn strategy.cast( strategyReference );\n\t\t}\n\t\telse {\n\t\t\tfinal var implementationClass =\n\t\t\t\t\tstrategyReference instanceof Class\n\t\t\t\t\t\t\t? (Class<? extends T>) strategyReference\n\t\t\t\t\t\t\t: selectStrategyImplementor( strategy, strategyReference.toString() );\n\t\t\ttry {\n\t\t\t\treturn creator.create( implementationClass );\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new StrategySelectionException(\n\t\t\t\t\t\tString.format( \"Could not instantiate named strategy class [%s]\",\n\t\t\t\t\t\t\t\timplementationClass.getName() ),\n\t\t\t\t\t\te","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java#L148-L184","documentation":"When resolveStrategy(strategy, reference, defaultResolver, creator) is called with a null strategy reference, it invokes the supplied defaultResolver callable; any exception it throws is wrapped as StrategySelectionException 'Default resolver threw exception'. The informative failure is in the cause chain: the default-resolution logic itself - for dialect resolution, typically automatic detection from the JDBC connection metadata.","triggerScenarios":"Omitting a strategy setting (e.g., no hibernate.dialect) so the default resolver runs, while the default logic fails - database metadata unreadable, unknown database or version, JDBC connection problems - during SessionFactory/EntityManagerFactory build.","commonSituations":"Boot without hibernate.dialect against an unsupported, unreachable, or not-yet-ready database; custom default-resolver lambdas that throw (NPE on missing config); CI pipelines starting the app before the database container is up.","solutions":["Set the strategy explicitly (hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect) to bypass default resolution entirely","Inspect the cause of the StrategySelectionException - it holds the real error from the resolver; fix that underlying issue","Ensure the database connection works and JDBC metadata is readable before building the factory (e.g., wait-for-it in CI)"],"exampleFix":"// before\n<property name=\"hibernate.dialect\" value=\"\"/> <!-- or absent; auto-detect fails -->\n\n// after\n<property name=\"hibernate.dialect\" value=\"org.hibernate.dialect.PostgreSQLDialect\"/>","handlingStrategy":"validation","validationCode":"// Fail fast on unusable defaults: set the dialect explicitly before boot\nif (!config.containsKey(\"hibernate.dialect\") && !isDatabaseReachable(jdbcUrl)) {\n    throw new IllegalStateException(\n        \"No hibernate.dialect set and the database is not reachable for auto-detection\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return strategySelector.resolveStrategy(Dialect.class, null, defaultResolver, creator);\n} catch (StrategySelectionException e) {\n    // the cause holds the real error from the default resolver (often JDBC metadata access)\n    throw new ConfigurationException(\"Default dialect resolution failed\", e.getCause());\n}","preventionTips":["Always set hibernate.dialect explicitly in production configs","In CI, wait for the database to accept connections before starting the app","Keep default-resolver lambdas defensive: never assume config keys or connections exist"],"tags":["hibernate","strategy","configuration","dialect","boot","jdbc"],"backgroundTag":"strategy-resolution-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}