quarkusio/quarkus · error · IllegalStateException

Mutiny.SessionFactory bean not found

Error message

Mutiny.SessionFactory bean not found

What it means

OpenedSessionsState.createSessionFactory resolves the Mutiny.SessionFactory CDI bean for a specific persistence unit using a @PersistenceUnit qualifier. If ArC has no such bean (for that named persistence unit), this IllegalStateException is thrown, meaning the reactive session factory was never registered for that PU.

Source

Thrown at extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/OpenedSessionsState.java:132

    private BaseKey<T> createBaseKey(String persistenceUnitName) {
        Mutiny.SessionFactory factory = sessionFactories.getValue(persistenceUnitName);
        Implementor implementor = (Implementor) ClientProxy.unwrap(factory);
        return new BaseKey<>(getSessionType(), implementor.getUuid());
    }

    private static Mutiny.SessionFactory createSessionFactory(String persistenceunitname) {
        Mutiny.SessionFactory sessionFactory;

        // Note that Mutiny.SessionFactory is @ApplicationScoped bean - it's safe to use the cached client proxy
        if (DEFAULT_PERSISTENCE_UNIT_NAME.equals(persistenceunitname)) {
            sessionFactory = Arc.container().instance(Mutiny.SessionFactory.class).get();
        } else {
            sessionFactory = Arc.container().instance(Mutiny.SessionFactory.class,
                    new PersistenceUnit.PersistenceUnitLiteral(persistenceunitname)).get();
        }

        if (sessionFactory == null) {
            throw new IllegalStateException("Mutiny.SessionFactory bean not found");
        }
        return sessionFactory;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify the persistence unit name matches one defined via quarkus.hibernate-orm.<name>.* config properties (default PU uses no name/"<default>")
  2. Ensure the injection/lookup uses the exact same name, e.g. @Inject @PersistenceUnit("myunit") Mutiny.SessionFactory
  3. Check that quarkus-hibernate-reactive (not just hibernate-orm) is configured for that persistence unit so the reactive SessionFactory bean exists
  4. Inspect startup logs for PU creation errors — a failed PU creation leaves no SessionFactory bean

Example fix

// before
@Inject
@PersistenceUnit("prod-unit")
Mutiny.SessionFactory sessionFactory; // name does not exist
// after
@Inject
@PersistenceUnit("users") // matches quarkus.hibernate-orm.users.* config
Mutiny.SessionFactory sessionFactory;
Defensive patterns

Strategy: validation

Validate before calling

import io.quarkus.arc.Arc;
import io.quarkus.hibernate.orm.PersistenceUnit;
import org.hibernate.reactive.mutiny.Mutiny;

Mutiny.SessionFactory sf = Arc.container()
    .instance(Mutiny.SessionFactory.class,
        new PersistenceUnit.PersistenceUnitLiteral("users"))
    .get();
if (sf == null) {
    throw new IllegalStateException("No Mutiny.SessionFactory for PU 'users'; check quarkus.hibernate-orm.users.* config");
}

Try / catch

try {
    return sessionFactory.withTransaction(...);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Mutiny.SessionFactory bean not found")) {
        throw new IllegalStateException("Persistence unit name has no reactive SessionFactory; verify @PersistenceUnit name and quarkus.hibernate-orm.<pu>.* config", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Requesting a session for a persistence unit name that has no registered Mutiny.SessionFactory bean — typically a misspelled or nonexistent persistence unit name in @PersistenceUnit("name")/@Inject, or bootstrapping before the Hibernate Reactive extension created the factory bean.

Common situations: Typos in persistence unit names in annotations or config; referencing a PU that only exists in the ORM (non-reactive) extension; ordering issues where a bean is resolved during startup before the PU is created; missing quarkus-hibernate-reactive configuration for that named PU.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/7d122b4b9a696901. Report an issue: GitHub.