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
With no persistence unit name supplied and multiple persistence units present, FastBootHibernatePersistenceProvider cannot decide which factory to build, so getEntityManagerFactoryBuilderOrNull throws PersistenceException("No name provided and multiple persistence units found"). Quarkus requires explicit disambiguation in multi-PU applications.
Source
Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java:181
log.tracef("Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s",
persistenceUnitName);
verifyProperties(properties);
// These are pre-parsed during image generation:
// Avoid processing 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 explicit persistence unit name to the API call.
- Use CDI-qualified injection (@PersistenceUnit("myPu")) instead of name-less lookups.
- Remove extra persistence unit definitions if only one is actually needed.
Example fix
// before
EntityManagerFactory emf = Persistence.createEntityManagerFactory(null);
// after
EntityManagerFactory emf = Persistence.createEntityManagerFactory("customers"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> puNames = PersistenceUnits.list(); // or count <persistence-unit> entries
if (puNames.size() > 1 && requestedName == null) {
throw new IllegalArgumentException("PU name required; units: " + puNames);
} Try / catch
try {
Persistence.createEntityManagerFactory(name);
} catch (PersistenceException e) {
if (e.getMessage().contains("No name provided and multiple persistence units")) {
throw new IllegalStateException("Specify a PU name: " + e.getMessage(), e);
} else throw e;
} Prevention
- Always pass an explicit PU name when the app defines more than one unit.
- Use CDI-qualified injection rather than name-less lookups.
- Document PU names for teams working with multi-PU apps.
When it happens
Trigger: getEntityManagerFactoryBuilderOrNull is invoked (via builder or getEntityManagerFactoryBuilder, e.g. name-less Persistence.createEntityManagerFactory) with persistenceUnitName == null while 2+ QuarkusPersistenceUnitDescriptors exist.
Common situations: Multiple persistence.xml <persistence-unit> entries or quarkus.hibernate-orm."name" configs; legacy libraries assuming a single default PU; tests booting an unnamed EMF.
Related errors
- Multiple ${AdditionalPersistenceUnitBuildItem} for persisten
- Persistence unit '<persistenceUnitName>' references mapping
- Attempting to boot a deactivated Hibernate ORM persistence u
- Unable to find an EntityManagerFactory for persistence unit
- Multiple instances of %1$s were found for persistence unit %
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/fdfa37a7ca190804.
Report an issue: GitHub.