hibernate/hibernate-orm · error · IllegalStateException
Map instantiation contained one or more arguments with no al
Error message
Map instantiation contained one or more arguments with no alias
What it means
Thrown by DynamicInstantiationResultImpl.createResultAssembler when a `select new map(...)` query has at least one argument without an alias. This is the primary validation point and fires during query-plan creation (usually on first execution of the query). Because the alias becomes the map key, an unaliased argument makes the Map result impossible to construct.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java:137
@SuppressWarnings("unchecked")
private DomainResultAssembler<R> resolveAssembler(
boolean areAllArgumentsAliased,
boolean areAnyArgumentsAliased,
List<String> duplicatedAliases,
List<ArgumentReader<?>> argumentReaders,
AssemblerCreationState creationState) {
if ( nature == DynamicInstantiationNature.LIST ) {
if ( LOG.isDebugEnabled() && areAnyArgumentsAliased ) {
LOG.debug( "One or more arguments for List dynamic instantiation (`new list(...)`) specified an alias; ignoring" );
}
return (DomainResultAssembler<R>)
new DynamicInstantiationAssemblerListImpl( (JavaType<List<?>>) javaType, argumentReaders );
}
else if ( nature == DynamicInstantiationNature.MAP ) {
if ( ! areAllArgumentsAliased ) {
throw new IllegalStateException( "Map instantiation contained one or more arguments with no alias" );
}
if ( !duplicatedAliases.isEmpty() ) {
throw new IllegalStateException(
"Map instantiation has arguments with duplicate aliases ["
+ StringHelper.join( ",", duplicatedAliases ) + "]"
);
}
return (DomainResultAssembler<R>)
new DynamicInstantiationAssemblerMapImpl( (JavaType<Map<?,?>>) javaType, argumentReaders );
}
else {
return assembler( areAllArgumentsAliased, duplicatedAliases, argumentReaders, creationState );
}
}
private DomainResultAssembler<R> assembler(
boolean areAllArgumentsAliased,
List<String> duplicatedAliases,View on GitHub (pinned to fad1729dce)
Solutions
- Alias every argument in the map instantiation: `select new map(e.id as id, e.name as name)`
- If a wrapper Map is genuinely wanted without keys, switch to `new list(...)` where aliases are optional
- For Criteria API, set an alias on each Selection before adding it to the compound selection
Example fix
// before
List<Map<?,?>> rows = session.createQuery("select new map(e.id, e.name) from Employee e", Map.class).getResultList();
// after
List<Map<?,?>> rows = session.createQuery("select new map(e.id as id, e.name as name) from Employee e", Map.class).getResultList(); Defensive patterns
Strategy: validation
Validate before calling
// With Criteria API, fail fast before execution if any selection lacks an alias
List<Selection<?>> parts = cb.construct? null : null; // (illustrative)
for (Selection<?> s : compoundSelections) {
if (s.getAlias() == null) throw new IllegalStateException("Selection needs alias for map instantiation: " + s);
} Prevention
- Alias all arguments when writing `new map(...)`; aliases are the map keys
- Cover every HQL query with a test that executes it once so plan-time validation runs in CI
- When migrating from `new list(...)` remember aliases go from optional to required
When it happens
Trigger: Executing `select new map(e.id, e.name) from Employee e` via `session.createQuery(...).getResultList()`; criteria query with DynamicInstantiationNature.MAP where selections lack aliases; first request after deployment triggers plan creation and fails.
Common situations: Developers writing `new map(...)` for the first time and not knowing aliases are mandatory; queries migrated from `new list(...)` or from native SQL; integration tests that only run the query late in the build, surfacing the failure at runtime instead of compile time.
Related errors
- alias for Map dynamic instantiation argument cannot be null
- Encountered duplicate alias for Map dynamic instantiation ar
- Map instantiation has arguments with duplicate aliases [{}]
- Entity join treats can not be aliased
- Root path treats can not be aliased - " + getNavigablePath()
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/94e412b884ecdcfa.
Report an issue: GitHub.