{"record":{"id":"72a084779d038129","repo":"quarkusio/quarkus","slug":"unable-to-find-an-entitymanagerfactory-for-persist","errorCode":null,"errorMessage":"Unable to find an EntityManagerFactory for persistence unit '%s'.","messagePattern":"Unable to find an EntityManagerFactory for persistence unit '(.+?)'\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/JPAConfig.java","lineNumber":105,"sourceCode":"        for (LazyPersistenceUnit pu : persistenceUnits.values()) {\n            allEntityManagerFactories.add(Tuple2.of(pu.name, getEntityManagerFactory(pu.name, pu.isReactive)));\n        }\n\n        return allEntityManagerFactories;\n    }\n\n    public EntityManagerFactory getEntityManagerFactory(String unitName, boolean reactive) {\n        LazyPersistenceUnit lazyPersistenceUnit = null;\n        if (unitName == null) {\n            if (persistenceUnits.size() == 1) {\n                lazyPersistenceUnit = persistenceUnits.values().iterator().next();\n            }\n        } else {\n            lazyPersistenceUnit = persistenceUnits.get(new PersistenceUnitKey(unitName, reactive));\n        }\n\n        if (lazyPersistenceUnit == null) {\n            throw new IllegalArgumentException(\n                    String.format(Locale.ROOT, \"Unable to find an EntityManagerFactory for persistence unit '%s'.%s\",\n                            unitName,\n                            deactivatedPersistenceUnitNames.contains(unitName)\n                                    ? \" This persistence unit is deactivated and should not have been created.\"\n                                    : \"\"));\n        }\n\n        return lazyPersistenceUnit.get();\n    }\n\n    /**\n     * Returns the registered, active persistence units.\n     *\n     * @return Set containing the names of all registered, actives persistence units.\n     */\n    public Set<String> getPersistenceUnits() {\n        return persistenceUnits.keySet().stream().map(k -> k.name()).collect(Collectors.toSet());\n    }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/JPAConfig.java#L87-L123","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar emf = jpaConfig.getEntityManagerFactory(\"customers\", false); // blocking\n// after (PU is configured as reactive)\nvar emf = jpaConfig.getEntityManagerFactory(\"customers\", true);","handlingStrategy":"validation","validationCode":"// Check PU presence via CDI-managed EMFs before use\nSet<String> names = jpaConfig.getEntityManagerFactories().keySet();\nif (!names.contains(puName)) {\n    throw new IllegalArgumentException(\"Unknown PU: \" + puName + \", known: \" + names);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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)"],"tags":["jpa","persistence-unit","quarkus","hibernate-orm","configuration"],"backgroundTag":"persistence-unit-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}