hibernate/hibernate-orm · error · IllegalStateException
CDI BeanManager is not known to be ready for use and the fal
Error message
CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java:114
return beanInstance;
}
@Override
public void initialize() {
if ( beanInstance != null ) {
return;
}
if ( beanManager == null ) {
try {
beanInstance = fallbackProducer.produceBeanInstance( beanType );
return;
}
catch (Exception e) {
// the CDI BeanManager is not know to be ready for use and the
// fallback-producer was unable to create the bean...
throw new IllegalStateException(
"CDI BeanManager is not known to be ready for use and the fallback-producer was unable to create the bean",
new NotYetReadyException( e )
);
}
}
final AnnotatedType<B> annotatedType;
try {
annotatedType = beanManager.createAnnotatedType( beanType );
}
catch (Exception e) {
throw new IllegalStateException( new NotYetReadyException( e ) );
}
try {
injectionTarget = beanManager.getInjectionTargetFactory( annotatedType ).createInjectionTarget( null );
creationalContext = beanManager.createCreationalContext( null );
View on GitHub (pinned to fad1729dce)
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.
Example fix
// before
public class AuditListener {
public AuditListener(AuditService svc) { ... } // only constructor takes arguments
}
// no CDI -> fallback 'new' fails -> IllegalStateException
// after
public class AuditListener {
public AuditListener() { } // public no-arg constructor for direct instantiation
} Defensive patterns
Strategy: validation
Validate before calling
// before boot: every class Hibernate may instantiate must be directly instantiable
static boolean directlyInstantiable(Class<?> c) {
try {
java.lang.reflect.Constructor<?> ctor = c.getDeclaredConstructor();
ctor.setAccessible(true);
return true;
} catch (ReflectiveOperationException e) {
return false;
}
}
if (!directlyInstantiable(AuditListener.class)) throw new IllegalStateException("missing no-arg ctor"); Try / catch
try {
emf = Persistence.createEntityManagerFactory("pu", props);
} catch (IllegalStateException e) {
if (e.getCause() instanceof org.hibernate.resource.beans.container.internal.NotYetReadyException) {
// no BeanManager AND fallback instantiation failed: fix ctor or configure CDI
throw new ConfigurationException("Bean neither CDI-resolvable nor directly instantiable", e);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not instantiate managed bean directly
- Bean class not known to CDI : {}
- Could not instantiate event listener '{}'
- Unable to instantiate StatementObserver - {}
- Could not instantiate named strategy class [{}]
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/fe8fa58013df138d.
Report an issue: GitHub.