{"record":{"id":"aa11f89473191989","repo":"hibernate/hibernate-orm","slug":"duplicate-named-stored-procedure","errorCode":null,"errorMessage":"Duplicate named stored procedure '{}'","messagePattern":"Duplicate named stored procedure '(.+?)'","errorType":"exception","errorClass":"DuplicateMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java","lineNumber":801,"sourceCode":"\t\treturn namedProcedureCallMap.get( name );\n\t}\n\n\t@Override\n\tpublic void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {\n\t\tnamedProcedureCallMap.values().forEach( definitionConsumer );\n\t}\n\n\t@Override\n\tpublic void addNamedProcedureCallDefinition(NamedProcedureCallDefinition definition) {\n\t\tif ( definition == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Named query definition is null\" );\n\t\t}\n\t\telse {\n\t\t\tfinal String name = definition.getRegistrationName();\n\t\t\tif ( !defaultNamedProcedureNames.contains( name ) ) {\n\t\t\t\tfinal var previous = namedProcedureCallMap.put( name, definition );\n\t\t\t\tif ( previous != null ) {\n\t\t\t\t\tthrow new DuplicateMappingException( DuplicateMappingException.Type.PROCEDURE, name );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic void addDefaultNamedProcedureCall(NamedProcedureCallDefinitionImpl definition) {\n\t\taddNamedProcedureCallDefinition( definition );\n\t\tdefaultNamedProcedureNames.add( definition.getRegistrationName() );\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// result-set mapping handling\n\n\t@Override\n\tpublic NamedResultSetMappingDescriptor getResultSetMapping(String name) {\n\t\treturn sqlResultSetMappingMap.get( name );","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java#L783-L819","documentation":"DuplicateMappingException(Type.PROCEDURE): two named stored-procedure registrations use the same name in one persistence unit. The collector even inserts the second mapping before throwing, but the effect is identical — the SessionFactory build aborts. Procedure names share the global registration namespace per factory.","triggerScenarios":"Two @NamedStoredProcedureQuery(name=\"X\") annotations; the same name declared via annotation in one module and orm.xml in another; a mapping file loaded twice.","commonSituations":"Copy-pasted stored-procedure annotations between entities, shared model jars defining the same procedure name, and copied orm.xml fragments that were never renamed.","solutions":["Search the project for the duplicated name from the message and rename one declaration","Check persistence.xml for doubly-listed mapping files","Namespace procedure names by feature (e.g. reporting.getDailyTotals) so independent modules cannot collide"],"exampleFix":"// before — both entities declare the same procedure name\n@NamedStoredProcedureQuery(name = \"syncUser\", procedureName = \"sync_user\")\n@NamedStoredProcedureQuery(name = \"syncUser\", procedureName = \"sync_contact\")\n\n// after\n@NamedStoredProcedureQuery(name = \"User.sync\", procedureName = \"sync_user\")\n@NamedStoredProcedureQuery(name = \"Contact.sync\", procedureName = \"sync_contact\")","handlingStrategy":"validation","validationCode":"static void assertNoDuplicateProcedureNames( Class<?>... entityClasses ) {\n    final Set<String> seen = new HashSet<>();\n    for ( final Class<?> c : entityClasses ) {\n        for ( final NamedStoredProcedureQuery q : c.getAnnotationsByType( NamedStoredProcedureQuery.class ) ) {\n            if ( !seen.add( q.name() ) ) {\n                throw new IllegalStateException( \"Duplicate @NamedStoredProcedureQuery name: \" + q.name() );\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    metadata.buildSessionFactory();\n} catch ( DuplicateMappingException e ) {\n    if ( e.getType() == DuplicateMappingException.Type.PROCEDURE ) {\n        throw new IllegalStateException( \"Duplicate named stored procedure '\" + e.getName() + \"' — rename one declaration\", e );\n    }\n    throw e;\n}","preventionTips":["Namespace stored-procedure names by feature or entity","Declare procedure queries in one module only","Boot the factory in CI to catch collisions between modules"],"tags":["hibernate","orm","jpa","java","bootstrap","stored-procedure","duplicate-mapping"],"backgroundTag":"duplicate-mapping-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}