hibernate/hibernate-orm · error · HibernateException

No result set mapping with given name '{}'

Error message

No result set mapping with given name '{}'

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java:2097

	protected static <R> void checkResultType(Class<R> expectedResultType, SelectionQuery<R> query) {
		final var resultType = query.getResultType();
		if ( !expectedResultType.isAssignableFrom( resultType ) ) {
			throw new QueryTypeMismatchException(
					String.format(
							Locale.ROOT,
							"Incorrect query result type: query produces '%s' but type '%s' was given",
							expectedResultType.getName(),
							resultType.getName()
					)
			);
		}
	}

	protected NamedResultSetMappingMemento getResultSetMappingMemento(String resultSetMappingName) {
		final var resultSetMappingMemento =
				namedObjectRepository().getResultSetMappingMemento( resultSetMappingName );
		if ( resultSetMappingMemento == null ) {
			throw new HibernateException( "No result set mapping with given name '" + resultSetMappingName + "'" );
		}
		return resultSetMappingMemento;
	}











	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Named Query
	@Override
	@Nonnull

View on GitHub (pinned to fad1729dce)

Solutions

  1. Verify the exact name string (case-sensitive) matches @SqlResultSetMapping(name = ...) and every reference to it.
  2. Declare the @SqlResultSetMapping on a mapped @Entity class (or in the same orm.xml) so bootstrap scanning picks it up.
  3. If metadata is split across persistence units, move the mapping into the unit that executes the query.

Example fix

// before (mapping on a non-scanned class)
@SqlResultSetMapping(name = "customerMapping", entities = @EntityResult(entityClass = Customer.class))
public abstract class CustomerMappings {}
// em.createNativeQuery(sql, "customerMapping"); // HibernateException: no mapping
// after (mapping on a mapped entity)
@Entity
@SqlResultSetMapping(name = "customerMapping", entities = @EntityResult(entityClass = Customer.class))
public class Customer { ... }
Defensive patterns

Strategy: try-catch

Validate before calling

// Optional startup check against the named-object repository (Hibernate SPI)
NamedObjectRepository repo = ((SessionFactoryImplementor) sessionFactory)
        .getQueryEngine().getNamedObjectRepository();
if (repo.getResultSetMappingMemento(mappingName) == null) {
    throw new IllegalStateException(
        "Missing @SqlResultSetMapping '" + mappingName + "' — fix mapping metadata");
}

Try / catch

try {
    return session.createNativeQuery(sql, mappingName);
} catch (HibernateException e) {
    if (e.getMessage() != null && e.getMessage().contains("No result set mapping")) {
        throw new ConfigurationError("Unknown SqlResultSetMapping '" + mappingName + "'", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/e6d7be695500da83. Report an issue: GitHub.