hibernate/hibernate-orm · critical · StrategySelectionException
Could not instantiate named dialect class [%s]
Error message
Could not instantiate named dialect class [%s]
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java:142
Dialect.class,
dialectReference,
(Dialect) null,
(dialectClass) -> {
try {
try {
if ( resolutionInfoSource != null ) {
return dialectClass.getConstructor( DialectResolutionInfo.class ).newInstance(
resolutionInfoSource.getDialectResolutionInfo()
);
}
}
catch (NoSuchMethodException nsme) {
}
return dialectClass.newInstance();
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new StrategySelectionException(
String.format( "Could not instantiate named dialect class [%s]", dialectClass.getName() ),
e
);
}
}
);
if ( dialect == null ) {
throw new HibernateException( "Unable to construct requested dialect [" + dialectReference + "]" );
}
else if ( Dialect.class.getPackage() == dialect.getClass().getPackage() ) {
DEPRECATION_LOGGER.automaticDialect( dialect.getClass().getSimpleName() );
}
return dialect;
}
catch (StrategySelectionException e) {
final String dialectFqn = dialectReference.toString();
if ( LEGACY_DIALECTS.contains( dialectFqn ) ) {
throw new StrategySelectionException(View on GitHub (pinned to fad1729dce)
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
Example fix
// before
public abstract class MyDialect extends PostgreSQLDialect {} // abstract -> InstantiationException
// after
public class MyDialect extends PostgreSQLDialect {
public MyDialect() {
super(DatabaseVersion.make(15, 2));
}
} Defensive patterns
Strategy: validation
Validate before calling
// validate the configured dialect class before bootstrap
Class<?> c = Class.forName(dialectClassName, false, getClass().getClassLoader());
int mods = c.getModifiers();
if ( Modifier.isAbstract(mods) || !Modifier.isPublic(mods)
|| !Modifier.isPublic(c.getConstructor().getModifiers()) ) {
throw new ConfigurationException("Dialect class must be public, concrete, with a public no-arg ctor: " + dialectClassName);
} Try / catch
try {
return builder.build();
} catch (StrategySelectionException e) {
Throwable root = e.getCause() instanceof InvocationTargetException ite ? ite.getTargetException() : e.getCause();
log.error("Dialect constructor failed: {}", root, e);
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Unable to instantiate named dialect resolver [<resolverImplN
- Could not instantiate event listener '{}'
- Unable to instantiate StatementObserver - {}
- Unable to construct requested dialect [<dialectReference>]
- Unable to determine Dialect without JDBC metadata (please se
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/1875a2511c85ceb6.
Report an issue: GitHub.