{"record":{"id":"1875a2511c85ceb6","repo":"hibernate/hibernate-orm","slug":"could-not-instantiate-named-dialect-class-s","errorCode":null,"errorMessage":"Could not instantiate named dialect class [%s]","messagePattern":"Could not instantiate named dialect class \\[(.+?)\\]","errorType":"exception","errorClass":"StrategySelectionException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java","lineNumber":142,"sourceCode":"\t\t\t\t\tDialect.class,\n\t\t\t\t\tdialectReference,\n\t\t\t\t\t(Dialect) null,\n\t\t\t\t\t(dialectClass) -> {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tif ( resolutionInfoSource != null ) {\n\t\t\t\t\t\t\t\t\treturn dialectClass.getConstructor( DialectResolutionInfo.class ).newInstance(\n\t\t\t\t\t\t\t\t\t\t\tresolutionInfoSource.getDialectResolutionInfo()\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (NoSuchMethodException nsme) {\n\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn dialectClass.newInstance();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (InstantiationException | IllegalAccessException | InvocationTargetException e) {\n\t\t\t\t\t\t\tthrow new StrategySelectionException(\n\t\t\t\t\t\t\t\t\tString.format( \"Could not instantiate named dialect class [%s]\", dialectClass.getName() ),\n\t\t\t\t\t\t\t\t\te\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t);\n\t\t\tif ( dialect == null ) {\n\t\t\t\tthrow new HibernateException( \"Unable to construct requested dialect [\" + dialectReference + \"]\" );\n\t\t\t}\n\t\t\telse if ( Dialect.class.getPackage() == dialect.getClass().getPackage() ) {\n\t\t\t\tDEPRECATION_LOGGER.automaticDialect( dialect.getClass().getSimpleName() );\n\t\t\t}\n\t\t\treturn dialect;\n\t\t}\n\t\tcatch (StrategySelectionException e) {\n\t\t\tfinal String dialectFqn = dialectReference.toString();\n\t\t\tif ( LEGACY_DIALECTS.contains( dialectFqn ) ) {\n\t\t\t\tthrow new StrategySelectionException(","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java#L124-L160","documentation":"DialectFactoryImpl.buildDialectInstance located the class named by hibernate.dialect via the strategy selector, but reflective construction failed with InstantiationException (abstract class or no usable constructor), IllegalAccessException (non-public constructor), or InvocationTargetException (constructor itself threw). The original exception is carried as the cause of StrategySelectionException.","triggerScenarios":"hibernate.dialect names a class that is abstract, lacks both a public no-arg constructor and a DialectResolutionInfo-taking constructor, has package-private constructors, or whose constructor throws (e.g. it rejects the database version it detects).","commonSituations":"Custom dialect subclasses with only a Dialect(DialectResolutionInfo) constructor that is not public; pointing hibernate.dialect at an interface or abstract base; a third-party dialect whose constructor fails on the detected metadata; constructor visibility changed by module/JPMS restrictions.","solutions":["Ensure the dialect class is concrete with a public no-arg constructor (or a public constructor accepting DialectResolutionInfo)","Read the nested cause: InvocationTargetException.getTargetException() shows the real constructor error","If using a custom subclass, expose `public MyDialect() { super(); }`","Prefer a supported built-in dialect FQN unless customization is required"],"exampleFix":"// before\npublic abstract class MyDialect extends PostgreSQLDialect {} // abstract -> InstantiationException\n\n// after\npublic class MyDialect extends PostgreSQLDialect {\n    public MyDialect() {\n        super(DatabaseVersion.make(15, 2));\n    }\n}","handlingStrategy":"validation","validationCode":"// validate the configured dialect class before bootstrap\nClass<?> c = Class.forName(dialectClassName, false, getClass().getClassLoader());\nint mods = c.getModifiers();\nif ( Modifier.isAbstract(mods) || !Modifier.isPublic(mods)\n        || !Modifier.isPublic(c.getConstructor().getModifiers()) ) {\n    throw new ConfigurationException(\"Dialect class must be public, concrete, with a public no-arg ctor: \" + dialectClassName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return builder.build();\n} catch (StrategySelectionException e) {\n    Throwable root = e.getCause() instanceof InvocationTargetException ite ? ite.getTargetException() : e.getCause();\n    log.error(\"Dialect constructor failed: {}\", root, e);\n    throw e;\n}","preventionTips":["Give every custom dialect a public no-arg constructor by convention","Unit-test instantiation of custom dialects (Class.forName(...).getConstructor().newInstance()) as part of the build"],"tags":["hibernate","dialect","reflection","bootstrap","configuration"],"backgroundTag":"dialect-instantiation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}