{"record":{"id":"3747bcf5dc441eb0","repo":"hibernate/hibernate-orm","slug":"unable-to-instantiate-specified-beancontainer","errorCode":null,"errorMessage":"Unable to instantiate specified BeanContainer","messagePattern":"Unable to instantiate specified BeanContainer","errorType":"exception","errorClass":"InstantiationException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/resource/beans/spi/ManagedBeanRegistryInitiator.java","lineNumber":113,"sourceCode":"\t\tfinal Object beanManager = settings.get( JAKARTA_CDI_BEAN_MANAGER );\n\t\treturn beanManager != null ? beanManager : settings.get( CDI_BEAN_MANAGER );\n\t}\n\n\tprivate BeanContainer interpretExplicitBeanContainer(Object explicitSetting, ServiceRegistry serviceRegistry) {\n\t\tif ( explicitSetting == null ) {\n\t\t\treturn null;\n\t\t}\n\t\telse if ( explicitSetting instanceof BeanContainer beanContainer ) {\n\t\t\treturn beanContainer;\n\t\t}\n\t\telse {\n\t\t\t// otherwise we ultimately need to resolve this to a class\n\t\t\tfinal Class<?> containerClass = containerClass( explicitSetting, serviceRegistry );\n\t\t\ttry {\n\t\t\t\treturn (BeanContainer) containerClass.newInstance();\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new InstantiationException( \"Unable to instantiate specified BeanContainer\", containerClass, e );\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static Class<?> containerClass(Object explicitSetting, ServiceRegistry serviceRegistry) {\n\t\tif ( explicitSetting instanceof Class<?> clazz ) {\n\t\t\treturn clazz;\n\t\t}\n\t\telse {\n\t\t\tfinal String name = explicitSetting.toString();\n\t\t\t// try the StrategySelector service\n\t\t\tfinal Class<?> selected =\n\t\t\t\t\tserviceRegistry.requireService( StrategySelector.class )\n\t\t\t\t\t\t\t.selectStrategyImplementor( BeanContainer.class, name );\n\t\t\treturn selected == null\n\t\t\t\t\t? serviceRegistry.requireService( ClassLoaderService.class ).classForName( name )\n\t\t\t\t\t: selected;\n\t\t}","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/beans/spi/ManagedBeanRegistryInitiator.java#L95-L131","documentation":"When 'hibernate.resource.beans.container' is configured with a class or class name (not a BeanContainer instance), ManagedBeanRegistryInitiator resolves the class and instantiates it reflectively via newInstance(). Any instantiation failure - no public no-arg constructor, abstract class, non-public class - is thrown as InstantiationException('Unable to instantiate specified BeanContainer') during SessionFactory bootstrap.","triggerScenarios":"The configured BeanContainer implementation has no public no-arg constructor (only constructors taking arguments), is abstract or an interface, or is non-public so reflective instantiation fails.","commonSituations":"Custom BeanContainer implementations written with constructor injection; refactors that removed the default constructor; typos resolving to the wrong class; copying configuration that names an abstract base class.","solutions":["Give the BeanContainer implementation a public no-arg constructor.","Pass a ready instance instead of a class name: props.put(\"hibernate.resource.beans.container\", new MyBeanContainer()).","Verify the configured FQCN actually names a concrete public class implementing org.hibernate.resource.beans.spi.BeanContainer.","Check the wrapped cause for constructor-side exceptions and fix them."],"exampleFix":"// before\nprops.put(\"hibernate.resource.beans.container\", MyBeanContainer.class.getName());\npublic MyBeanContainer(DataSource ds) { ... } // no no-arg ctor -> InstantiationException\n\n// after\npublic MyBeanContainer() { ... } // public no-arg ctor\n// or pass an instance: props.put(\"hibernate.resource.beans.container\", new MyBeanContainer());","handlingStrategy":"validation","validationCode":"// validate an explicitly configured container class before boot\nstatic void assertValidContainer(String fqcn) throws Exception {\n    Class<?> c = Class.forName(fqcn);\n    if (!org.hibernate.resource.beans.spi.BeanContainer.class.isAssignableFrom(c)\n            || Modifier.isAbstract(c.getModifiers()) || !Modifier.isPublic(c.getModifiers())) {\n        throw new IllegalArgumentException(\"Not a public concrete BeanContainer: \" + fqcn);\n    }\n    c.getConstructor(); // requires public no-arg ctor\n}","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props);\n} catch (org.hibernate.InstantiationException e) {\n    // configured BeanContainer class could not be instantiated: fix ctor or pass an instance\n    throw new ConfigurationException(\"Bad hibernate.resource.beans.container class\", e);\n}","preventionTips":["Give custom BeanContainer implementations a public no-arg constructor.","Prefer passing a pre-built instance over a class name.","Cover the container wiring with a boot smoke test in CI."],"tags":["hibernate","configuration","reflection","bean-container","bootstrap"],"backgroundTag":"invalid-configuration-class","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}