hibernate/hibernate-orm · error · IllegalArgumentException

Result-set mapping name is null: {}

Error message

Result-set mapping name is null: {}

What it means

A non-null result-set mapping descriptor carried a null registration name. The exception appends the descriptor's toString() to help locate it. Because @SqlResultSetMapping is referenced by name from @NamedNativeQuery(resultSetMapping=...), a nameless mapping is unusable and bootstrap stops.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:835

	@Override
	public NamedResultSetMappingDescriptor getResultSetMapping(String name) {
		return sqlResultSetMappingMap.get( name );
	}

	@Override
	public void visitNamedResultSetMappingDefinition(Consumer<NamedResultSetMappingDescriptor> definitionConsumer) {
		sqlResultSetMappingMap.values().forEach( definitionConsumer );
	}

	@Override
	public void addResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
		if ( resultSetMappingDescriptor == null ) {
			throw new IllegalArgumentException( "Result-set mapping was null" );
		}
		else {
			final String name = resultSetMappingDescriptor.getRegistrationName();
			if ( name == null ) {
				throw new IllegalArgumentException( "Result-set mapping name is null: " + resultSetMappingDescriptor );
			}
			else if ( !defaultSqlResultSetMappingNames.contains( name ) ) {
				applyResultSetMapping( resultSetMappingDescriptor );
			}
		}
	}

	public void applyResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
		final var old = sqlResultSetMappingMap.put(
				resultSetMappingDescriptor.getRegistrationName(),
				resultSetMappingDescriptor
		);
		if ( old != null ) {
			throw new DuplicateMappingException(
					DuplicateMappingException.Type.RESULT_SET_MAPPING,
					resultSetMappingDescriptor.getRegistrationName()
			);
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Identify the descriptor via the toString() output printed in the message
  2. Add the name attribute in orm.xml, or set the name programmatically before registration
  3. Verify the native query's resultSetMapping attribute references exactly that name

Example fix

<!-- before -->
<sql-result-set-mapping>
    <column-result name="id"/>
</sql-result-set-mapping>

<!-- after -->
<sql-result-set-mapping name="UserByIdMapping">
    <column-result name="id"/>
</sql-result-set-mapping>
Defensive patterns

Strategy: validation

Validate before calling

if ( d == null || d.getRegistrationName() == null ) {
    throw new IllegalStateException( "Result-set mapping missing name: " + d );
}
collector.addResultSetMapping( d );

Type guard

static boolean hasRegistrationName( NamedResultSetMappingDescriptor d ) {
    return d != null && d.getRegistrationName() != null && !d.getRegistrationName().isBlank();
}

Try / catch

try {
    metadata.buildSessionFactory();
} catch ( IllegalArgumentException e ) {
    if ( e.getMessage() != null && e.getMessage().startsWith( "Result-set mapping name is null" ) ) {
        // message contains descriptor.toString() — use it to locate the mapping
        throw new IllegalStateException( "Nameless result-set mapping: " + e.getMessage(), e );
    }
    throw e;
}

Prevention

When it happens

Trigger: An orm.xml <sql-result-set-mapping> element without a name attribute; a builder/contributor constructing the descriptor without setting its registration name.

Common situations: Hand-edited orm.xml, migration tooling rewriting mappings, and programmatic descriptor construction from absent config keys.

Related errors


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