hibernate/hibernate-orm · error · NoSuchBeanException
Bean class not known to CDI: {}
Error message
Bean class not known to CDI: {} What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java:200
}
@Override
protected Instance<B> resolveContainerInstance() {
final Instance<Object> root;
try {
root = beanManager.createInstance();
}
catch (Exception e) {
// this indicates that the BeanManager is not yet ready to use,
// which should be considered an error
throw new NotYetReadyException( e );
}
try {
return root.select( beanType, new NamedBeanQualifier( beanName ) );
}
catch (Exception e) {
throw new NoSuchBeanException( "Bean class not known to CDI: " + beanType.getName(), e );
}
}
@Override
protected B produceFallbackInstance() {
return fallbackProducer.produceBeanInstance( beanName, beanType );
}
}
}
View on GitHub (pinned to fad1729dce)
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.
Example fix
// before
// Hibernate asked for a bean named "auditListener" but only this exists:
@ApplicationScoped @Named("auditor")
public class AuditListener { }
// -> NoSuchBeanException: Bean class not known to CDI
// after - match the requested name
@ApplicationScoped @Named("auditListener")
public class AuditListener { } Defensive patterns
Strategy: validation
Validate before calling
// verify named beans referenced by configuration exist before boot
@Inject BeanManager bm;
void verifyNamedBean(String name, Class<?> type) {
if (bm.getBeans(type, new NamedLiteral(name)).isEmpty()) {
throw new IllegalStateException("No CDI bean '" + name + "' of type " + type.getName());
}
} Try / catch
try {
emf = Persistence.createEntityManagerFactory("pu", props);
} catch (PersistenceException e) {
if (e.getCause() instanceof org.hibernate.resource.beans.container.spi.NoSuchBeanException nsb) {
// named bean missing: register a bean with the exact name/qualifier, then retry
throw new ConfigurationException(nsb.getMessage(), nsb);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Bean class not known to CDI : {}
- ExtendedBeanManager.LifecycleListener callback not yet calle
- CDI BeanManager is not known to be ready for use and the fal
- Could not instantiate managed bean directly
- Multiple BeanContainer service implementations found (set 'h
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/9d998e224090bc76.
Report an issue: GitHub.