{"record":{"id":"8844cf94079ce972","repo":"hibernate/hibernate-orm","slug":"the-class-could-not-be-instantiated","errorCode":null,"errorMessage":"The {} class [{}] could not be instantiated","messagePattern":"The (.+?) class \\[(.+?)\\] could not be instantiated","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java","lineNumber":1734,"sourceCode":"\t\t\t\ttry {\n\t\t\t\t\tinstanceClass = (Class<? extends T>) Class.forName( className );\n\t\t\t\t}\n\t\t\t\tcatch (ClassNotFoundException e) {\n\t\t\t\t\tthrow new IllegalArgumentException( \"Can't load class: \" + className, e );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException( \"The provided \" + settingName\n\t\t\t\t\t+ \" setting value [\" + settingValue + \"] is not supported\" );\n\t\t}\n\n\t\tif ( instanceClass != null ) {\n\t\t\ttry {\n\t\t\t\treturn instanceClass.newInstance();\n\t\t\t}\n\t\t\tcatch (InstantiationException | IllegalAccessException e) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"The \" + clazz.getSimpleName() +\" class [\" + instanceClass + \"] could not be instantiated\",\n\t\t\t\t\t\te\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Exposed to extensions: see Hibernate Reactive\n\t */\n\tpublic StandardServiceRegistry getStandardServiceRegistry() {\n\t\treturn standardServiceRegistry;\n\t}\n}\n","sourceCodeStart":1716,"sourceCodeEnd":1752,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java#L1716-L1752","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic class MyInterceptor implements Interceptor {\n    private final Registry registry;\n    public MyInterceptor(Registry registry) { this.registry = registry; } // no no-arg ctor\n}\n\n// after\nsettings.put(\"hibernate.session_factory.interceptor\", new MyInterceptor(registry)); // pass instance","handlingStrategy":"validation","validationCode":"// verify constructibility before handing the class name to Hibernate\nClass<?> c = Class.forName(fqcn);\nif (Modifier.isAbstract(c.getModifiers()) || !Modifier.isPublic(c.getModifiers())) throw new IllegalStateException(fqcn + \" must be a public concrete class\");\nc.getDeclaredConstructor().newInstance(); // dry-run the same reflective construction","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always give configurable strategy classes a public no-arg constructor.","For classes needing dependencies, construct them yourself and pass the instance."],"tags":["hibernate","jpa","configuration","instantiation","reflection"],"backgroundTag":"configured-class-instantiation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}