{"record":{"id":"e6d7be695500da83","repo":"hibernate/hibernate-orm","slug":"no-result-set-mapping-with-given-name","errorCode":null,"errorMessage":"No result set mapping with given name '{}'","messagePattern":"No result set mapping with given name '(.+?)'","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java","lineNumber":2097,"sourceCode":"\tprotected static <R> void checkResultType(Class<R> expectedResultType, SelectionQuery<R> query) {\n\t\tfinal var resultType = query.getResultType();\n\t\tif ( !expectedResultType.isAssignableFrom( resultType ) ) {\n\t\t\tthrow new QueryTypeMismatchException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Incorrect query result type: query produces '%s' but type '%s' was given\",\n\t\t\t\t\t\t\texpectedResultType.getName(),\n\t\t\t\t\t\t\tresultType.getName()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\tprotected NamedResultSetMappingMemento getResultSetMappingMemento(String resultSetMappingName) {\n\t\tfinal var resultSetMappingMemento =\n\t\t\t\tnamedObjectRepository().getResultSetMappingMemento( resultSetMappingName );\n\t\tif ( resultSetMappingMemento == null ) {\n\t\t\tthrow new HibernateException( \"No result set mapping with given name '\" + resultSetMappingName + \"'\" );\n\t\t}\n\t\treturn resultSetMappingMemento;\n\t}\n\n\n\n\n\n\n\n\n\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Named Query\n\t@Override\n\t@Nonnull","sourceCodeStart":2079,"sourceCodeEnd":2115,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java#L2079-L2115","documentation":"getResultSetMappingMemento() resolves a named @SqlResultSetMapping in the factory's named-object repository; a null lookup — the name was never registered during bootstrap — throws HibernateException('No result set mapping with given name <name>'). The mapping must be part of the deployed mapping metadata before any query can reference it.","triggerScenarios":"createNativeQuery(sql, \"customerMapping\") or @NamedNativeQuery(resultSetMapping = \"customerMapping\") where no @SqlResultSetMapping with that exact, case-sensitive name exists: typo, mapping declared on a class Hibernate does not scan (non-entity/DTO/abstract), orm.xml entry missing or in another persistence unit.","commonSituations":"Renaming mappings in one place but not in referencing @NamedNativeQuery attributes; putting @SqlResultSetMapping on a DTO or utility class instead of a mapped @Entity; module splits where the annotated entity is not in the persistence unit; annotation/XML duplication drift after refactors.","solutions":["Verify the exact name string (case-sensitive) matches @SqlResultSetMapping(name = ...) and every reference to it.","Declare the @SqlResultSetMapping on a mapped @Entity class (or in the same orm.xml) so bootstrap scanning picks it up.","If metadata is split across persistence units, move the mapping into the unit that executes the query."],"exampleFix":"// before (mapping on a non-scanned class)\n@SqlResultSetMapping(name = \"customerMapping\", entities = @EntityResult(entityClass = Customer.class))\npublic abstract class CustomerMappings {}\n// em.createNativeQuery(sql, \"customerMapping\"); // HibernateException: no mapping\n// after (mapping on a mapped entity)\n@Entity\n@SqlResultSetMapping(name = \"customerMapping\", entities = @EntityResult(entityClass = Customer.class))\npublic class Customer { ... }","handlingStrategy":"try-catch","validationCode":"// Optional startup check against the named-object repository (Hibernate SPI)\nNamedObjectRepository repo = ((SessionFactoryImplementor) sessionFactory)\n        .getQueryEngine().getNamedObjectRepository();\nif (repo.getResultSetMappingMemento(mappingName) == null) {\n    throw new IllegalStateException(\n        \"Missing @SqlResultSetMapping '\" + mappingName + \"' — fix mapping metadata\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.createNativeQuery(sql, mappingName);\n} catch (HibernateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"No result set mapping\")) {\n        throw new ConfigurationError(\"Unknown SqlResultSetMapping '\" + mappingName + \"'\", e);\n    }\n    throw e;\n}","preventionTips":["Reference mapping names via shared constants, not string literals","Keep @SqlResultSetMapping next to the @Entity that owns the query","Add a startup assertion that every mapping name used in code is registered"],"tags":["hibernate","native-query","result-set-mapping","named-query","orm"],"backgroundTag":"named-query-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}