{"record":{"id":"d431aa0b0a6773bf","repo":"quarkusio/quarkus","slug":"entities-do-not-support-being-attached-to-several","errorCode":null,"errorMessage":" entities do not support being attached to several persistence units:","messagePattern":" entities do not support being attached to several persistence units:","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-orm-panache/deployment/src/main/java/io/quarkus/hibernate/orm/panache/deployment/EntityToPersistenceUnitUtil.java","lineNumber":56,"sourceCode":"            if (!isCandidate) {\n                continue;\n            }\n\n            if (selectedPersistenceUnits.size() == 1) {\n                result.put(entityName, selectedPersistenceUnits.iterator().next());\n            } else {\n                violatingEntities.put(entityName, selectedPersistenceUnits);\n            }\n        }\n\n        if (violatingEntities.size() > 0) {\n            StringBuilder message = new StringBuilder(\n                    String.format(\"%s entities do not support being attached to several persistence units:\\n\", source));\n            for (Map.Entry<String, Set<String>> violatingEntityEntry : violatingEntities\n                    .entrySet()) {\n                message.append(\"\\t- \").append(violatingEntityEntry.getKey()).append(\" is attached to: \")\n                        .append(String.join(\",\", violatingEntityEntry.getValue()));\n                throw new IllegalStateException(message.toString());\n            }\n        }\n\n        return result;\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":63,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-orm-panache/deployment/src/main/java/io/quarkus/hibernate/orm/panache/deployment/EntityToPersistenceUnitUtil.java#L38-L63","documentation":"The Hibernate ORM Panache deployment validates that each entity is associated with exactly one persistence unit. determineEntityPersistenceUnits collects entity-to-PU mappings, and when an entity appears in more than one persistence unit (violatingEntities non-empty) it builds a message and throws IllegalStateException. (Note: the throw sits inside the loop, so it aborts on the first violating entity.)","triggerScenarios":"A @Entity managed by Panache is resolvable under two persistence units defined in quarkus.datasource.* / quarkus.hibernate-orm.* configs — e.g. two <persistence-unit> definitions or two named Hibernate ORM configs both scanning the same entity packages.","commonSituations":"Multi-datasource setups where entity classes are in a package scanned by both persistence units; forgetting to restrict entities per PU; sharing an entity jar across two Quarkus Hibernate ORM configurations.","solutions":["Scope each entity to a single persistence unit by restricting the packages scanned per PU (quarkus.hibernate-orm.\"pu\".packages)","Remove duplicate persistence-unit definitions or exclude shared entities from one of them","Move entities only used by one datasource into a dedicated package and configure each PU's packages accordingly"],"exampleFix":"// before: both PUs scan the same package\nquarkus.hibernate-orm.pu1.packages=com.example.entity\nquarkus.hibernate-orm.pu2.packages=com.example.entity\n// after: split packages\nquarkus.hibernate-orm.pu1.packages=com.example.entity.first\nquarkus.hibernate-orm.pu2.packages=com.example.entity.second","handlingStrategy":"validation","validationCode":"// before build, ensure no entity package is scanned by two PUs\nMap<String, List<String>> entityToPus = collectEntityPus(config); // from your build step\nList<String> violations = entityToPus.entrySet().stream()\n        .filter(e -> e.getValue().size() > 1)\n        .map(e -> e.getKey() + \" -> \" + e.getValue())\n        .toList();\nif (!violations.isEmpty()) throw new IllegalStateException(\"Entities in multiple PUs: \" + violations);","typeGuard":null,"tryCatchPattern":"try {\n    determineEntityPersistenceUnits(...);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"several persistence units\")) {\n        throw new IllegalStateException(\"Restrict each entity package to one quarkus.hibernate-orm.<pu>.packages\", e);\n    }\n    throw e;\n}","preventionTips":["Configure distinct quarkus.hibernate-orm.\"pu\".packages per persistence unit","Avoid sharing entity jars between multiple datasources/PU configs","Review entity package layout when adding a second datasource"],"tags":["hibernate-orm","panache","persistence-unit","config"],"backgroundTag":"entity-multiple-persistence-units","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"}