{"record":{"id":"0f1bb3990fe70162","repo":"hibernate/hibernate-orm","slug":"class-or-package-level-namedstoredprocedurequery","errorCode":null,"errorMessage":"Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'","messagePattern":"Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java","lineNumber":975,"sourceCode":"\t\t\t}\n\n\t\t\tif ( BOOT_LOGGER.isTraceEnabled() ) {\n\t\t\t\tBOOT_LOGGER.bindingNamedQuery( registrationName,\n\t\t\t\t\t\tnamedQuery.query().replace( '\\n', ' ' ) );\n\t\t\t}\n\n\t\t\tfinal var definition = NamedHqlSelectionDefinitionImpl.from( namedQuery, location );\n\t\t\tcontext.getMetadataCollector().addNamedQuery( definition );\n\t\t}\n\t}\n\n\tpublic static void bindNamedStoredProcedureQuery(\n\t\t\tNamedStoredProcedureQuery namedStoredProcedureQuery,\n\t\t\tMetadataBuildingContext context,\n\t\t\tboolean isDefault) {\n\t\tif ( namedStoredProcedureQuery != null ) {\n\t\t\tif ( namedStoredProcedureQuery.name().isBlank() ) {\n\t\t\t\tthrow new AnnotationException( \"Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'\" );\n\t\t\t}\n\n\t\t\tfinal var definition = new NamedProcedureCallDefinitionImpl( namedStoredProcedureQuery );\n\t\t\tfinal var collector = context.getMetadataCollector();\n\t\t\tif ( isDefault ) {\n\t\t\t\tcollector.addDefaultNamedProcedureCall( definition );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcollector.addNamedProcedureCallDefinition( definition );\n\t\t\t}\n\t\t\tBOOT_LOGGER.boundStoredProcedureQuery(\n\t\t\t\t\tdefinition.getRegistrationName(),\n\t\t\t\t\tdefinition.getProcedureName() );\n\t\t}\n\t}\n\n\tpublic static void bindSqlResultSetMapping(\n\t\t\tSqlResultSetMapping resultSetMappingAnn,","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java#L957-L993","documentation":"QueryBinder.bindNamedStoredProcedureQuery registers a jakarta.persistence @NamedStoredProcedureQuery; if namedStoredProcedureQuery.name() is blank, AnnotationException is thrown during metadata building. The name is the key later passed to createNamedStoredProcedureQuery(name), so it cannot be empty.","triggerScenarios":"@NamedStoredProcedureQuery(name = \"\", procedureName = \"SP_DO_WORK\") on an entity or in orm.xml equivalent; blank (empty/whitespace) name triggers the check before the procedure definition is registered.","commonSituations":"Wrapping legacy stored procedures and leaving the registration name for later; code-generating procedure mappings with an unfilled template; refactoring that moves procedureName but clears name.","solutions":["Set a unique non-blank name, conventionally EntityName.procedureName.","If names come from generated sources, fix the generator/template to always emit the key.","Audit orm.xml files too when annotations look correct but the error persists."],"exampleFix":"// before\n@NamedStoredProcedureQuery(name = \"\", procedureName = \"SP_CALC_TOTALS\")\n\n// after\n@NamedStoredProcedureQuery(name = \"Order.calcTotals\", procedureName = \"SP_CALC_TOTALS\")","handlingStrategy":"validation","validationCode":"@Test void procedureQueriesHaveNames() {\n    NamedStoredProcedureQuery q = Order.class.getAnnotation(NamedStoredProcedureQuery.class);\n    if (q != null) assertTrue(!q.name().isBlank());\n}","typeGuard":null,"tryCatchPattern":"try {\n    metadata = sources.buildMetadata();\n} catch (AnnotationException e) {\n    failBuild(\"Named procedure query registration failed: \" + e.getMessage());\n}","preventionTips":["Name procedures EntityName.procedureName at authoring time.","Validate orm.xml procedure entries with the same non-blank rule."],"tags":["hibernate","orm","stored-procedure","named-query","annotation","boot"],"backgroundTag":"named-query-missing-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}