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
- Pass the persistence unit name explicitly: Persistence.createEntityManagerFactory("<pu-name>")
- Use Quarkus injection (inject EntityManagerFactory / Mutiny.SessionFactory) instead of manual bootstrap
- Reduce to a single persistence unit if only one is needed
- 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
- Always pass an explicit persistence unit name when more than one PU exists
- Prefer CDI injection of EntityManagerFactory/SessionFactory over Persistence bootstrap
- List configured PUs (quarkus.hibernate-orm.* keys) before refactoring
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
- No name provided and multiple persistence units found
- Attempting to boot a deactivated Hibernate Reactive persiste
- Mutiny.SessionFactory bean not found
- %s entities do not support being attached to several persist
- Entity '%s' was not found. Did you forget to annotate your P
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c97be84e46b62be3.
Report an issue: GitHub.