{"record":{"id":"8e7ab1703f191299","repo":"hibernate/hibernate-orm","slug":"duplicate-named-entity-graph-s","errorCode":null,"errorMessage":"Duplicate named entity graph '%s'","messagePattern":"Duplicate named entity graph '(.+?)'","errorType":"exception","errorClass":"DuplicateMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java","lineNumber":689,"sourceCode":"\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Named EntityGraph handling\n\n\t@Override\n\tpublic NamedEntityGraphDefinition getNamedEntityGraph(String name) {\n\t\treturn namedEntityGraphMap.get( name );\n\t}\n\n\t@Override\n\tpublic Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs() {\n\t\treturn namedEntityGraphMap;\n\t}\n\n\t@Override\n\tpublic void addNamedEntityGraph(NamedEntityGraphDefinition definition) {\n\t\tfinal String name = definition.name();\n\t\tfinal var previous = namedEntityGraphMap.put( name, definition );\n\t\tif ( previous != null ) {\n\t\t\tthrow new DuplicateMappingException( DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );\n\t\t}\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Named query handling\n\n\tpublic NamedHqlQueryDefinition<?> getNamedHqlQueryMapping(String name) {\n\t\tif ( name == null ) {\n\t\t\tthrow new IllegalArgumentException( \"null is not a valid query name\" );\n\t\t}\n\t\treturn namedQueryMap.get( name );\n\t}\n\n\t@Override\n\tpublic void visitNamedHqlQueryDefinitions(Consumer<NamedHqlQueryDefinition<?>> definitionConsumer) {\n\t\tnamedQueryMap.values().forEach( definitionConsumer );\n\t}","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java#L671-L707","documentation":"Named entity graphs are registered by name; addNamedEntityGraph throws DuplicateMappingException(Type.NAMED_ENTITY_GRAPH) with 'Duplicate named entity graph' when a graph with that name is already registered - two @NamedEntityGraph / @NamedEntityGraphs (or XML <named-entity-graph>) declarations share one name.","triggerScenarios":"The same @NamedEntityGraph(name=\"...\") appearing on two entities or twice in an @NamedEntityGraphs container; duplicate <named-entity-graph name=...> entries in orm.xml; or programmatic double registration hitting the put-then-check at InFlightMetadataCollectorImpl.java:685-690.","commonSituations":"Copy-pasted graph annotations; merged modules defining generic 'overview'/'detail' graphs with identical names; refactoring that moved annotations without renaming them.","solutions":["Rename one of the graphs named in the message to be unique and update lookups (EntityManager.getEntityGraph(name))","Delete the duplicated graph declaration if it was accidental","Consolidate: define shared graphs once and reference them rather than redefining per entity"],"exampleFix":"// before\n@NamedEntityGraph(name = \"overview\", ...)  // on User\n@NamedEntityGraph(name = \"overview\", ...)  // on Order -> throws\n\n// after\n@NamedEntityGraph(name = \"User.overview\", ...)\n@NamedEntityGraph(name = \"Order.overview\", ...)","handlingStrategy":"try-catch","validationCode":"// Pre-check programmatic graph registration\nif (metadata.getNamedEntityGraphs().containsKey(graph.name())) {\n    throw new IllegalStateException(\"entity graph name already used: \" + graph.name());\n}","typeGuard":null,"tryCatchPattern":"try {\n    metadata.buildSessionFactory();\n}\ncatch (DuplicateMappingException e) {\n    // message names the duplicated graph: rename one @NamedEntityGraph\n    // and update EntityManager.getEntityGraph(name) call sites\n}","preventionTips":["Use a naming convention for graph names (Entity.purpose, e.g. User.overview)","Search for a graph name before adding a new @NamedEntityGraph with a generic name"],"tags":["hibernate","jpa","entity-graph","duplicate"],"backgroundTag":"duplicate-entity-graph","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}