{"record":{"id":"9d998e224090bc76","repo":"hibernate/hibernate-orm","slug":"bean-class-not-known-to-cdi-9d998e","errorCode":null,"errorMessage":"Bean class not known to CDI: {}","messagePattern":"Bean class not known to CDI: (.+?)","errorType":"exception","errorClass":"NoSuchBeanException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java","lineNumber":200,"sourceCode":"\t\t}\n\n\t\t@Override\n\t\tprotected Instance<B> resolveContainerInstance() {\n\t\t\tfinal Instance<Object> root;\n\t\t\ttry {\n\t\t\t\troot = beanManager.createInstance();\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\t// this indicates that the BeanManager is not yet ready to use,\n\t\t\t\t// which should be considered an error\n\t\t\t\tthrow new NotYetReadyException( e );\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn root.select( beanType, new NamedBeanQualifier( beanName ) );\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new NoSuchBeanException( \"Bean class not known to CDI: \" + beanType.getName(), e );\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tprotected B produceFallbackInstance() {\n\t\t\treturn fallbackProducer.produceBeanInstance( beanName, beanType );\n\t\t}\n\t}\n}\n","sourceCodeStart":182,"sourceCodeEnd":210,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java#L182-L210","documentation":"The named variant of ContainerManagedLifecycleStrategy resolves beans with Instance.select(beanType, new NamedBeanQualifier(beanName)) - i.e. by type plus a name qualifier. If that lookup throws, Hibernate wraps it as NoSuchBeanException('Bean class not known to CDI: <fqcn>'): CDI is ready but no bean of the requested type with the requested name/qualifier exists.","triggerScenarios":"Hibernate requests a bean by name qualifier (ManagedBeanRegistry bean-by-name lookups, e.g. a named listener or strategy instance) and CDI finds no matching bean: the named bean is not defined, the qualifier name does not match, or the bean has a different type than requested.","commonSituations":"Configuration referencing a bean by name that was renamed or never registered; multiple beans where the name qualifier no longer disambiguates; deployments where the named bean lives in an unscanned archive.","solutions":["Define a CDI bean of the exact requested type with the exact requested name/qualifier (@Named(\"...\") or a matching custom qualifier).","Verify the name string in the Hibernate configuration matches the bean's qualifier character-for-character.","Ensure the bean's archive is discovered (beans.xml / bean-defining annotation) and the bean is not vetoed.","If the name lookup is unnecessary, drop it and resolve by type instead."],"exampleFix":"// before\n// Hibernate asked for a bean named \"auditListener\" but only this exists:\n@ApplicationScoped @Named(\"auditor\")\npublic class AuditListener { }\n// -> NoSuchBeanException: Bean class not known to CDI\n\n// after - match the requested name\n@ApplicationScoped @Named(\"auditListener\")\npublic class AuditListener { }","handlingStrategy":"validation","validationCode":"// verify named beans referenced by configuration exist before boot\n@Inject BeanManager bm;\n\nvoid verifyNamedBean(String name, Class<?> type) {\n    if (bm.getBeans(type, new NamedLiteral(name)).isEmpty()) {\n        throw new IllegalStateException(\"No CDI bean '\" + name + \"' of type \" + type.getName());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props);\n} catch (PersistenceException e) {\n    if (e.getCause() instanceof org.hibernate.resource.beans.container.spi.NoSuchBeanException nsb) {\n        // named bean missing: register a bean with the exact name/qualifier, then retry\n        throw new ConfigurationException(nsb.getMessage(), nsb);\n    }\n    throw e;\n}","preventionTips":["Define every name-referenced bean with a matching @Named/qualifier value.","Validate name strings against actual bean names in a startup check.","Avoid naming beans in configuration when type-based resolution suffices."],"tags":["hibernate","cdi","named-bean","dependency-injection","weld"],"backgroundTag":"cdi-bean-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}