hibernate/hibernate-orm · error · IllegalArgumentException
The {} class [{}] could not be instantiated
Error message
The {} class [{}] could not be instantiated What it means
Thrown by EntityManagerFactoryBuilderImpl.loadSettingInstance() as an IllegalArgumentException when the class resolved from a setting exists but instanceClass.newInstance() fails - because the class has no accessible no-arg constructor, is abstract or an interface, or its constructor is non-public. The message names the expected type and the concrete class that failed to instantiate.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java:1734
try {
instanceClass = (Class<? extends T>) Class.forName( className );
}
catch (ClassNotFoundException e) {
throw new IllegalArgumentException( "Can't load class: " + className, e );
}
}
}
else {
throw new IllegalArgumentException( "The provided " + settingName
+ " setting value [" + settingValue + "] is not supported" );
}
if ( instanceClass != null ) {
try {
return instanceClass.newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException(
"The " + clazz.getSimpleName() +" class [" + instanceClass + "] could not be instantiated",
e
);
}
}
else {
return null;
}
}
/**
* Exposed to extensions: see Hibernate Reactive
*/
public StandardServiceRegistry getStandardServiceRegistry() {
return standardServiceRegistry;
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Add a public no-arg constructor to the configured class.
- If the class must be created with arguments, construct it yourself and pass the instance (or the Class) instead of the class name.
- Make sure the class is concrete and, if nested, static.
- If the constructor itself threw, check the cause for the underlying error in your initialization code.
Example fix
// before
public class MyInterceptor implements Interceptor {
private final Registry registry;
public MyInterceptor(Registry registry) { this.registry = registry; } // no no-arg ctor
}
// after
settings.put("hibernate.session_factory.interceptor", new MyInterceptor(registry)); // pass instance Defensive patterns
Strategy: validation
Validate before calling
// verify constructibility before handing the class name to Hibernate Class<?> c = Class.forName(fqcn); if (Modifier.isAbstract(c.getModifiers()) || !Modifier.isPublic(c.getModifiers())) throw new IllegalStateException(fqcn + " must be a public concrete class"); c.getDeclaredConstructor().newInstance(); // dry-run the same reflective construction
Prevention
- Always give configurable strategy classes a public no-arg constructor.
- For classes needing dependencies, construct them yourself and pass the instance.
When it happens
Trigger: Configuring a class for a strategy setting that has only a constructor with arguments, is abstract, is a non-static inner class, or has a package-private/private no-arg constructor; newInstance() requires a public no-arg constructor.
Common situations: Handing a class that needs constructor injection (Spring beans) directly via a String setting; refactoring a helper class to abstract with concrete subclasses while the config still points at it; using an old implementation jar compiled against a different Hibernate API whose ctor throws.
Related errors
- Could not instantiate named strategy class [%s]
- Unable to instantiate specified event listener class:
- Unable to instantiate ScanningProvider `%s`
- Unable to instantiate Scanner `%s`
- Unable to instantiate configured ArchiveDescriptorFactory -
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/8844cf94079ce972.
Report an issue: GitHub.