hibernate/hibernate-orm · error · IllegalStateException
ExtendedBeanManager.LifecycleListener callback not yet calle
Error message
ExtendedBeanManager.LifecycleListener callback not yet called: CDI not (yet) usable
What it means
CdiBeanContainerExtendedAccessImpl defers CDI usage to the ExtendedBeanManager lifecycle: usableBeanManager is set only after the container fires the bean-manager-initialized callback and is nulled in beforeBeanManagerDestroyed. getUsableBeanManager() throws IllegalStateException when Hibernate needs a bean before that callback has fired, or after CDI has been torn down.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/CdiBeanContainerExtendedAccessImpl.java:81
}
}
@Override
public void beanManagerInitialized(BeanManager beanManager) {
this.usableBeanManager = beanManager;
forEachBean( ContainedBeanImplementor::initialize );
}
@Override
public void beforeBeanManagerDestroyed(BeanManager beanManager) {
stop();
this.usableBeanManager = null;
}
@Override
public BeanManager getUsableBeanManager() {
if ( usableBeanManager == null ) {
throw new IllegalStateException( "ExtendedBeanManager.LifecycleListener callback not yet called: CDI not (yet) usable" );
}
return usableBeanManager;
}
@Internal
public BeanManager getBeanManager() {
return usableBeanManager;
}
private class BeanImpl<B> implements ContainedBeanImplementor<B> {
private final Class<B> beanType;
private final BeanLifecycleStrategy lifecycleStrategy;
private final BeanInstanceProducer fallbackProducer;
private ContainedBeanImplementor<B> delegateContainedBean;
private BeanImpl(
Class<B> beanType,View on GitHub (pinned to fad1729dce)
Solutions
- Build the EntityManagerFactory only after CDI is fully started (e.g. in an AfterDeploymentValidation observer).
- In plain Java SE, pass the ready BeanManager via 'jakarta.persistence.bean.manager' instead of an ExtendedBeanManager.
- Fix shutdown ordering: close the EntityManagerFactory before stopping the CDI container.
- Ensure exactly one lifecycle observer is registered so the initialized callback actually reaches Hibernate.
Example fix
// before
Map<String, Object> props = Map.of("jakarta.persistence.bean.manager", extendedBeanManager);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu", props);
// created too early: callback not yet fired -> IllegalStateException
// after
void onCdiReady(@Observes AfterDeploymentValidation adv, BeanManager bm) {
this.emf = Persistence.createEntityManagerFactory(
"pu", Map.of("jakarta.persistence.bean.manager", bm));
} Defensive patterns
Strategy: retry
Try / catch
// defer EMF creation until CDI signals readiness; retry bean-dependent boot once started
void init() {
if (!cdiStarted) { pendingBoot = this::init; return; }
try {
this.emf = Persistence.createEntityManagerFactory("pu", props);
} catch (IllegalStateException e) {
// 'ExtendedBeanManager.LifecycleListener callback not yet called'
throw new BootOrderException("Build the EMF after the CDI container started", e);
}
} Prevention
- Create the EntityManagerFactory inside an AfterDeploymentValidation observer.
- Close the EntityManagerFactory before shutting down the CDI container.
- In Java SE, prefer passing a fully started BeanManager instead of an ExtendedBeanManager.
When it happens
Trigger: Hibernate resolves a CDI-managed bean (entity listener, converter, or any BeanContainer consumer) while usableBeanManager is null: during EntityManagerFactory/SessionFactory bootstrap before the CDI container finished startup, or during shutdown when the SessionFactory still resolves beans after CDI was destroyed.
Common situations: SE apps passing Weld's ExtendedBeanManager; app-server or Quarkus-style boot where EMF creation races CDI initialization; tests that build the EMF before the CDI container starts; shutdown ordering where the CDI container closes before the EntityManagerFactory.
Related errors
- Bean class not known to CDI : {}
- Bean class not known to CDI: {}
- Multiple BeanContainer service implementations found (set 'h
- A bean manager was provided via 'jakarta.persistence.bean.ma
- The {storageEngine} storage engine is not supported
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/93ba28ffe9cd3673.
Report an issue: GitHub.