{"record":{"id":"084133cfe028741c","repo":"hibernate/hibernate-orm","slug":"namedstoredprocedurequery-s-specified-both-resu","errorCode":null,"errorMessage":"NamedStoredProcedureQuery [%s] specified both resultClasses and resultSetMappings","messagePattern":"NamedStoredProcedureQuery \\[(.+?)\\] specified both resultClasses and resultSetMappings","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/query/internal/NamedProcedureCallDefinitionImpl.java","lineNumber":66,"sourceCode":"\tprivate final String[] resultSetMappings;\n\tprivate final ParameterDefinitions parameterDefinitions;\n\tprivate final Map<String, Object> hints;\n\n\tpublic NamedProcedureCallDefinitionImpl(@Nonnull NamedStoredProcedureQuery annotation) {\n\t\tregisteredName = annotation.name();\n\t\tprocedureName = annotation.procedureName();\n\t\thints = new QueryHintDefinition( registeredName, annotation.hints() ).getHintsMap();\n\n\t\tresultClasses = annotation.resultClasses();\n\t\tresultSetMappings = annotation.resultSetMappings();\n\n\t\tparameterDefinitions = new ParameterDefinitions( annotation.parameters() );\n\n\t\tfinal boolean specifiesResultClasses = resultClasses != null && resultClasses.length > 0;\n\t\tfinal boolean specifiesResultSetMappings = resultSetMappings != null && resultSetMappings.length > 0;\n\n\t\tif ( specifiesResultClasses && specifiesResultSetMappings ) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"NamedStoredProcedureQuery [%s] specified both resultClasses and resultSetMappings\",\n\t\t\t\t\t\t\tregisteredName\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic String getRegistrationName() {\n\t\treturn registeredName;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic QueryFlushMode getQueryFlushMode() {\n\t\treturn QueryFlushMode.DEFAULT;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/query/internal/NamedProcedureCallDefinitionImpl.java#L48-L84","documentation":"JPA lets @NamedStoredProcedureQuery describe its results either with resultClasses or with resultSetMappings, never both. NamedProcedureCallDefinitionImpl's constructor checks both annotation attributes during bootstrap and throws this MappingException (naming the query's registered name) when both arrays are non-empty, because Hibernate cannot decide which result shape applies.","triggerScenarios":"An @NamedStoredProcedureQuery annotation that sets both resultClasses = {X.class} and resultSetMappings = {\"...\"}; both arrays non-empty triggers the MappingException while Hibernate processes annotated entities during EntityManagerFactory/SessionFactory build.","commonSituations":"Adding resultSetMappings to an existing annotation and forgetting to remove resultClasses; copy-paste from another named query; migrations between the two result strategies; IDE auto-completion filling in both attributes.","solutions":["Keep exactly one of the two attributes: delete resultClasses if you want SqlResultSetMapping-based results, or delete resultSetMappings if you want entity-class results","If you need both shapes, define two separate @NamedStoredProcedureQuery entries with different names","Rebuild/redeploy so the corrected annotation is reprocessed"],"exampleFix":"// before\n@NamedStoredProcedureQuery(\n  name = \"countOrders\",\n  procedureName = \"count_orders\",\n  resultClasses = { OrderCount.class },\n  resultSetMappings = { \"OrderCountMapping\" }) // both set -> MappingException\n\n// after\n@NamedStoredProcedureQuery(\n  name = \"countOrders\",\n  procedureName = \"count_orders\",\n  resultSetMappings = { \"OrderCountMapping\" })","handlingStrategy":"validation","validationCode":"// Deployment-time check over annotated classes\nfor (AnnotatedElement el : annotatedElements) {\n    NamedStoredProcedureQuery q = el.getAnnotation(NamedStoredProcedureQuery.class);\n    if (q != null && q.resultClasses().length > 0 && q.resultSetMappings().length > 0) {\n        throw new IllegalStateException(\"@NamedStoredProcedureQuery \" + q.name()\n            + \" must not set both resultClasses and resultSetMappings\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory = metadata.buildSessionFactory();\n} catch (MappingException e) {\n    if (e.getMessage().contains(\"resultClasses and resultSetMappings\")) {\n        // identify the named query from the message and remove one attribute\n    }\n    throw e;\n}","preventionTips":["Treat resultClasses and resultSetMappings as mutually exclusive in code review","Add an ArchUnit/reflection test asserting at most one is set per named stored procedure query","Run a full EntityManagerFactory build in CI to catch annotation conflicts before deploy"],"tags":["hibernate","jpa","stored-procedure","named-query","annotation","boot"],"backgroundTag":"conflicting-annotation-attributes","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}