{"record":{"id":"fe8fa58013df138d","repo":"hibernate/hibernate-orm","slug":"cdi-beanmanager-is-not-known-to-be-ready-for-use-a","errorCode":null,"errorMessage":"CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean","messagePattern":"CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java","lineNumber":114,"sourceCode":"\n\t\t\treturn beanInstance;\n\t\t}\n\n\t\t@Override\n\t\tpublic void initialize() {\n\t\t\tif ( beanInstance != null ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( beanManager == null ) {\n\t\t\t\ttry {\n\t\t\t\t\tbeanInstance = fallbackProducer.produceBeanInstance( beanType );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t// the CDI BeanManager is not know to be ready for use and the\n\t\t\t\t\t// fallback-producer was unable to create the bean...\n\t\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\t\"CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean\",\n\t\t\t\t\t\t\tnew NotYetReadyException( e )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfinal AnnotatedType<B> annotatedType;\n\t\t\ttry {\n\t\t\t\tannotatedType = beanManager.createAnnotatedType( beanType );\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new IllegalStateException( new NotYetReadyException( e ) );\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tinjectionTarget = beanManager.getInjectionTargetFactory( annotatedType ).createInjectionTarget( null );\n\t\t\t\tcreationalContext = beanManager.createCreationalContext( null );\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java#L96-L132","documentation":"JpaCompliantLifecycleStrategy.BeanImpl initializes beans: with no BeanManager available (beanManager == null), it falls back to the BeanInstanceProducer - by default reflective direct instantiation. When that fallback also fails, Hibernate throws IllegalStateException('CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean') wrapping NotYetReadyException. The requested unnamed bean could be neither CDI-resolved nor directly instantiated.","triggerScenarios":"An unnamed bean is requested while no usable BeanManager exists and the class cannot be reflectively instantiated: missing or inaccessible no-arg constructor (final/inner non-static class, JPMS strong encapsulation blocking setAccessible), abstract/interface class, or a constructor that throws.","commonSituations":"SE apps without CDI where an entity listener or integrator class has only constructor-injection constructors; Kotlin/Scala classes without a default constructor; JPMS deployments where reflective access is denied; constructors that fail on missing dependencies.","solutions":["Give the class a public no-arg constructor so the fallback producer can instantiate it.","Make the class a public top-level or static nested class (non-static inner classes cannot be reflectively constructed).","Configure a real BeanContainer/BeanManager so the CDI path (not the fallback) creates the bean.","If the constructor throws, fix that root cause first - it is wrapped in the exception chain."],"exampleFix":"// before\npublic class AuditListener {\n    public AuditListener(AuditService svc) { ... } // only constructor takes arguments\n}\n// no CDI -> fallback 'new' fails -> IllegalStateException\n\n// after\npublic class AuditListener {\n    public AuditListener() { } // public no-arg constructor for direct instantiation\n}","handlingStrategy":"validation","validationCode":"// before boot: every class Hibernate may instantiate must be directly instantiable\nstatic boolean directlyInstantiable(Class<?> c) {\n    try {\n        java.lang.reflect.Constructor<?> ctor = c.getDeclaredConstructor();\n        ctor.setAccessible(true);\n        return true;\n    } catch (ReflectiveOperationException e) {\n        return false;\n    }\n}\n\nif (!directlyInstantiable(AuditListener.class)) throw new IllegalStateException(\"missing no-arg ctor\");","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props);\n} catch (IllegalStateException e) {\n    if (e.getCause() instanceof org.hibernate.resource.beans.container.internal.NotYetReadyException) {\n        // no BeanManager AND fallback instantiation failed: fix ctor or configure CDI\n        throw new ConfigurationException(\"Bean neither CDI-resolvable nor directly instantiable\", e);\n    }\n    throw e;\n}","preventionTips":["Give every Hibernate-managed bean class a public no-arg constructor.","Configure a real BeanContainer when constructor injection is required.","Static-analyze listener classes for no-arg constructors in the build."],"tags":["hibernate","cdi","reflection","bean-instantiation","entity-listener"],"backgroundTag":"bean-instantiation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}