quarkusio/quarkus · error · IllegalArgumentException
Unable to find an EntityManagerFactory for persistence unit
Error message
Unable to find an EntityManagerFactory for persistence unit '%s'.
What it means
JPAConfig cannot resolve a persistence unit name (and reactive flag) to a lazily-created EntityManagerFactory. It is thrown when application code requests an EMF for a persistence unit that was never registered by the Hibernate ORM extension, or only under the other (blocking/reactive) flavor. The message also appends a hint when the unit exists but was deactivated at build time.
Source
Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/JPAConfig.java:105
for (LazyPersistenceUnit pu : persistenceUnits.values()) {
allEntityManagerFactories.add(Tuple2.of(pu.name, getEntityManagerFactory(pu.name, pu.isReactive)));
}
return allEntityManagerFactories;
}
public EntityManagerFactory getEntityManagerFactory(String unitName, boolean reactive) {
LazyPersistenceUnit lazyPersistenceUnit = null;
if (unitName == null) {
if (persistenceUnits.size() == 1) {
lazyPersistenceUnit = persistenceUnits.values().iterator().next();
}
} else {
lazyPersistenceUnit = persistenceUnits.get(new PersistenceUnitKey(unitName, reactive));
}
if (lazyPersistenceUnit == null) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Unable to find an EntityManagerFactory for persistence unit '%s'.%s",
unitName,
deactivatedPersistenceUnitNames.contains(unitName)
? " This persistence unit is deactivated and should not have been created."
: ""));
}
return lazyPersistenceUnit.get();
}
/**
* Returns the registered, active persistence units.
*
* @return Set containing the names of all registered, actives persistence units.
*/
public Set<String> getPersistenceUnits() {
return persistenceUnits.keySet().stream().map(k -> k.name()).collect(Collectors.toSet());
}View on GitHub (pinned to e1c734241f)
Solutions
- Verify the persistence unit name matches quarkus.hibernate-orm.persistence-unit.<name> configuration exactly (default name is "default" if not set).
- If using Hibernate Reactive, ensure the call requests reactive=true (or false for blocking) to match how the PU was configured.
- Check that the PU is active: quarkus.hibernate-orm.persistence-unit.<name>.active=true (and datasource active), and that no runtime profile deactivates it.
- Ensure quarkus-hibernate-orm (or quarkus-hibernate-reactive) is a dependency and entities are annotated (@Entity) so the PU is created.
Example fix
// before
var emf = jpaConfig.getEntityManagerFactory("customers", false); // blocking
// after (PU is configured as reactive)
var emf = jpaConfig.getEntityManagerFactory("customers", true); Defensive patterns
Strategy: validation
Validate before calling
// Check PU presence via CDI-managed EMFs before use
Set<String> names = jpaConfig.getEntityManagerFactories().keySet();
if (!names.contains(puName)) {
throw new IllegalArgumentException("Unknown PU: " + puName + ", known: " + names);
} Prevention
- Use constant/config values for PU names, never string literals scattered in code
- In multi-PU apps, inject EntityManager with @PersistenceUnit("name") rather than manual lookups
- Verify PU active flags when running with test profiles
- Match reactive flag to the extension used (hibernate-reactive vs hibernate-orm)
When it happens
Trigger: Calling getEntityManagerFactory(unitName, reactive) with a name that does not match any configured quarkus.hibernate-orm...persistence-unit name; requesting the reactive variant of a blocking-only PU (or vice versa); accessing a PU that was deactivated (quarkus.hibernate-orm.active=false or persistence-unit.<name>.active=false); a typo in the PU name passed to injectEMF/EMF lookups.
Common situations: Multi-persistence-unit applications where code uses the default name '' (default) but the PU was given an explicit name; switching an entity to Hibernate Reactive without flipping the reactive flag; deactivated PUs in integration-test profiles; classpath-app code copied between projects with different PU names.
Related errors
- @PersistenceUnit annotations are not supported at the class
- Multiple ${AdditionalPersistenceUnitBuildItem} for persisten
- Unable to find file referenced in '<puPropertyKey(persistenc
- This PersistenceProvider does not support createEntityManage
- No name provided and multiple persistence units found
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/72a084779d038129.
Report an issue: GitHub.