quarkusio/quarkus · error · PersistenceException

No name provided and multiple persistence units found

Error message

No name provided and multiple persistence units found

What it means

FastBootHibernateReactivePersistenceProvider.locateEntityManagerFactoryBuilder resolves persistence unit descriptors. When createEntityManagerFactory is called without a persistence unit name and more than one persistence unit is registered, the selection is ambiguous, so a PersistenceException is thrown.

Source

Thrown at extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/FastBootHibernateReactivePersistenceProvider.java:157

            Map properties) {
        log.tracef("Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s",
                persistenceUnitName);

        verifyProperties(properties);

        // These are pre-parsed during image generation:
        // Processing only the reactive descriptors
        final List<QuarkusPersistenceUnitDescriptor> units = PersistenceUnitsHolder.getPersistenceUnitDescriptors()
                .stream()
                .filter(d -> d.isReactive())
                .toList();

        log.debugf("Located %s persistence units; checking each", units.size());

        if (persistenceUnitName == null && units.size() > 1) {
            // no persistence-unit name to look for was given and we found multiple
            // persistence-units
            throw new PersistenceException("No name provided and multiple persistence units found");
        }

        for (QuarkusPersistenceUnitDescriptor persistenceUnit : units) {
            log.debugf(
                    "Checking persistence-unit [name=%s, explicit-provider=%s] against incoming persistence unit name [%s]",
                    persistenceUnit.getName(), persistenceUnit.getProviderClassName(), persistenceUnitName);

            final boolean matches = persistenceUnitName == null
                    || persistenceUnit.getName().equals(persistenceUnitName);
            if (!matches) {
                log.debugf("Excluding from consideration '%s' due to name mismatch", persistenceUnit.getName());
                continue;
            }

            // See if we (Hibernate) are the persistence provider
            if (!isProvider(persistenceUnit)) {
                log.debug("Excluding from consideration due to provider mismatch");
                continue;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass the persistence unit name explicitly: Persistence.createEntityManagerFactory("<pu-name>")
  2. Use Quarkus injection (inject EntityManagerFactory / Mutiny.SessionFactory) instead of manual bootstrap
  3. Reduce to a single persistence unit if only one is needed
  4. Check quarkus.hibernate-orm.* config to confirm the exact PU names

Example fix

// before
EntityManagerFactory emf = Persistence.createEntityManagerFactory(null); // ambiguous

// after
EntityManagerFactory emf = Persistence.createEntityManagerFactory("customers");
Defensive patterns

Strategy: type-guard

Validate before calling

long puCount = configuredPersistenceUnits().size();
boolean nameRequired = puCount > 1;
if (nameRequired && puName == null) throw new IllegalArgumentException("PU name required");

Type guard

boolean unambiguousBootstrap(String puName, int unitCount) {
    return puName != null || unitCount == 1;
}

Try / catch

try {
    emf = Persistence.createEntityManagerFactory(puName);
} catch (PersistenceException e) {
    if (e.getMessage().contains("multiple persistence units")) { puName = pickDefaultPu(); }
    throw e;
}

Prevention

When it happens

Trigger: Calling Persistence.createEntityManagerFactory() (or Hibernate's bootstrap) with null name while the app defines 2+ persistence units (multiple named PUs configured via quarkus.hibernate-orm."name".*); detected in getEntityManagerFactoryBuilderOrNull.

Common situations: Adding a second persistence unit and existing code still calls createEntityManagerFactory with no arguments; library code bootstrapping EMFs without a name; porting a multi-PU Spring/SE app to Quarkus Hibernate Reactive.

Related errors


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