{"record":{"id":"5192185295a90de8","repo":"quarkusio/quarkus","slug":"panacheentity-s-cannot-be-defined-for-usage-in-519218","errorCode":null,"errorMessage":"PanacheEntity '%s' cannot be defined for usage in several persistence units which is not supported. The following persistence units were found: %s.","messagePattern":"PanacheEntity '(.+?)' cannot be defined for usage in several persistence units which is not supported\\. The following persistence units were found: (.+?)\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-reactive-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/kotlin/deployment/HibernateReactivePanacheKotlinProcessor.java","lineNumber":135,"sourceCode":"\n        Map<String, Set<String>> collectedEntityToPersistenceUnits;\n        boolean incomplete;\n        if (jpaModelPersistenceUnitMapping.isPresent()) {\n            collectedEntityToPersistenceUnits = jpaModelPersistenceUnitMapping.get().getEntityToPersistenceUnits();\n            incomplete = jpaModelPersistenceUnitMapping.get().isIncomplete();\n        } else {\n            collectedEntityToPersistenceUnits = new HashMap<>();\n            // This happens if there is no persistence unit, in which case we definitely know this metadata is complete.\n            incomplete = false;\n        }\n\n        Map<String, String> panacheEntityToPersistenceUnit = new HashMap<>();\n        for (Map.Entry<String, Set<String>> entry : collectedEntityToPersistenceUnits.entrySet()) {\n            String entityName = entry.getKey();\n            List<String> selectedPersistenceUnits = new ArrayList<>(entry.getValue());\n            boolean isPanacheEntity = modelClasses.contains(entityName);\n            if (selectedPersistenceUnits.size() > 1 && isPanacheEntity) {\n                throw new IllegalStateException(String.format(\n                        \"PanacheEntity '%s' cannot be defined for usage in several persistence units which is not supported. The following persistence units were found: %s.\",\n                        entityName, String.join(\",\", selectedPersistenceUnits)));\n            }\n\n            panacheEntityToPersistenceUnit.put(entityName, selectedPersistenceUnits.get(0));\n        }\n        // This is called even if there are no entity types, so that Panache gets properly initialized.\n        recorder.addEntityTypesToPersistenceUnit(panacheEntityToPersistenceUnit, incomplete);\n    }\n\n    private void processCompanions(CombinedIndexBuildItem index, BuildProducer<BytecodeTransformerBuildItem> transformers,\n            List<String> classNamesToRegisterForReflection,\n            KotlinPanacheCompanionEnhancer enhancer) {\n\n        Set<org.jboss.jandex.Type> typeParameters = new HashSet<>();\n        for (ClassInfo classInfo : index.getComputingIndex()\n                .getAllKnownImplementations(TYPE_BUNDLE.entityCompanionBase().dotName())) {\n            if (classInfo.name().equals(TYPE_BUNDLE.entityCompanion().dotName())) {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-reactive-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/kotlin/deployment/HibernateReactivePanacheKotlinProcessor.java#L117-L153","documentation":"When one Panache entity is collected as belonging to more than one persistence unit, the build step cannot decide which persistence unit it maps to; Kotlin Panache entities are tied to a single persistence unit. The processor throws at augmentation time.","triggerScenarios":"processEntities finds a class annotated as a Panache entity (modelClasses contains it) whose name appears in collectedEntityToPersistenceUnits with a set of more than one persistence unit.","commonSituations":"Configuring multiple persistence units (quarkus.hibernate-orm.\"pu1\" and \"pu2\") and having a single @Entity extend PanacheEntity; entities not excluded from one PU via configuration.","solutions":["Assign each Panache entity to exactly one persistence unit (configure per-PU entity packages or move the entity)","Convert the entity from Panache active-record style to a plain @Entity with EntityManager so it can be used across PUs","Restructure to one persistence unit if multi-PU isn't truly required"],"exampleFix":"// before (one entity, two PUs configured) -> fails\n@Entity\npublic class Customer extends PanacheKotlinEntity\n// after: split PUs so Customer belongs to only one,\n// e.g. move entities to a package scoped to a single named PU","handlingStrategy":"validation","validationCode":"var pus = configuredPersistenceUnitsFor(entityClass);\nif (pus.size() > 1) throw new IllegalStateException(\"Entity \" + entityClass + \" maps to multiple PUs\");","typeGuard":null,"tryCatchPattern":"try { build } catch (IllegalStateException e) { if (e.getMessage().contains(\"several persistence units\")) log.error(\"Reassign entity to one PU: {}\", e.getMessage()); throw e; }","preventionTips":["Keep one Panache active-record entity per persistence unit","Use plain @Entity + EntityManager for shared entities","Document PU-to-package mapping"],"tags":["quarkus","panache","hibernate-reactive","kotlin","persistence-unit"],"backgroundTag":"entity-multi-persistence-unit","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}