{"record":{"id":"07314f34b5c269fc","repo":"hibernate/hibernate-orm","slug":"bean-class-not-known-to-cdi","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":162,"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 );\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( beanType );\n\t\t}\n\t}\n\n\tprivate static class NamedBeanImpl<B> extends AbstractBeanImpl<B> {\n\t\tprivate final String beanName;\n\n\t\tprivate NamedBeanImpl(\n\t\t\t\tString beanName,\n\t\t\t\tClass<B> beanType,\n\t\t\t\tBeanInstanceProducer fallbackProducer,\n\t\t\t\tBeanManager beanManager) {\n\t\t\tsuper( beanType, fallbackProducer, beanManager );","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java#L144-L180","documentation":"ContainerManagedLifecycleStrategy resolves beans from a ready CDI BeanManager via Instance.select(beanType). If that lookup throws (typically UnsatisfiedResolutionException - no resolvable bean of the type), Hibernate wraps it as NoSuchBeanException('Bean class not known to CDI : <fqcn>'). It means CDI is up, but has no bean matching the requested type.","triggerScenarios":"Hibernate asks the BeanContainer for a bean by type - an @EntityListeners class, an attribute converter, or a service requested via the managed-bean registry - and CDI cannot resolve it: class not in a bean archive, no bean-defining annotation, class non-public or vetoed, or an ambiguous resolution between alternatives.","commonSituations":"Entity listeners packaged in a jar without beans.xml under annotated-only discovery; classes missing @ApplicationScoped/@Dependent; Quarkus/Weld SE extensions vetoing beans; deployments split across classloaders so the bean archive is not scanned.","solutions":["Make the class a CDI bean: add a bean-defining annotation (@ApplicationScoped, @Dependent) and ensure the class is public with a usable constructor.","Add META-INF/beans.xml with <bean-discovery-mode>all</bean-discovery-mode> to the jar containing the class.","Remove ambiguity: enable exactly one bean/alternative of that type via @Priority.","Check for @Vetoed on the class or an extensions vetoing it, and remove the veto."],"exampleFix":"// before\npublic class AuditListener { } // no bean-defining annotation -> not discovered\n@Entity @EntityListeners(AuditListener.class)\npublic class Order { ... }\n// -> NoSuchBeanException: Bean class not known to CDI\n\n// after\n@ApplicationScoped\npublic class AuditListener { }\n// or add META-INF/beans.xml with bean-discovery-mode=all to that jar","handlingStrategy":"validation","validationCode":"// startup self-check: every class Hibernate will resolve as a bean must be resolvable in CDI\n@Inject Instance<Object> instance;\n\nvoid verifyBean(Class<?> required) {\n    if (!instance.select(required).isResolvable()) {\n        throw new IllegalStateException(required + \" is not a resolvable CDI bean\");\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        // make the class a CDI bean or add beans.xml, then retry boot\n        throw new ConfigurationException(nsb.getMessage(), nsb);\n    }\n    throw e;\n}","preventionTips":["Annotate entity listeners and converters with a bean-defining scope, or ship beans.xml with discovery mode all.","Run a startup check that every Hibernate-resolved bean type resolves in the CDI container.","Keep listener classes public and instantiable so the fallback path can also work."],"tags":["hibernate","cdi","entity-listener","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"}