hibernate/hibernate-orm · error · IllegalStateException
Encountered duplicate alias for Map dynamic instantiation ar
Error message
Encountered duplicate alias for Map dynamic instantiation argument [{}] What it means
Thrown while building the assembler for `select new map(...)`: two or more arguments were given the same alias. Map keys must be unique, so duplicate aliases make the entry set ambiguous. As with error 3180, the equivalent check in DynamicInstantiationResultImpl (error 3183) usually fires earlier at query-plan creation; this message appears via direct assembler construction paths.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationAssemblerMapImpl.java:42
*/
public class DynamicInstantiationAssemblerMapImpl implements DomainResultAssembler<Map<?,?>> {
private final JavaType<Map<?,?>> mapJavaType;
private final List<ArgumentReader<?>> argumentReaders;
public DynamicInstantiationAssemblerMapImpl(
JavaType<Map<?,?>> mapJavaType,
List<ArgumentReader<?>> argumentReaders) {
this.mapJavaType = mapJavaType;
this.argumentReaders = argumentReaders;
final Set<String> aliases = new HashSet<>();
for ( var argumentReader : argumentReaders ) {
if ( argumentReader.getAlias() == null ) {
throw new IllegalStateException( "alias for Map dynamic instantiation argument cannot be null" );
}
if ( ! aliases.add( argumentReader.getAlias() ) ) {
throw new IllegalStateException( "Encountered duplicate alias for Map dynamic instantiation argument [" + argumentReader.getAlias() + "]" );
}
}
}
private DynamicInstantiationAssemblerMapImpl(
List<ArgumentReader<?>> argumentReaders,
JavaType<Map<?,?>> mapJavaType) {
this.mapJavaType = mapJavaType;
this.argumentReaders = argumentReaders;
}
@Override
public JavaType<Map<?,?>> getAssembledJavaType() {
return mapJavaType;
}
@Override
public Map<?,?> assemble(View on GitHub (pinned to fad1729dce)
Solutions
- Make every alias in the `new map(...)` list unique, e.g. `select new map(a.id as aId, b.id as bId)`
- Re-run the query - the validation happens before any SQL is executed
- If aliases are generated programmatically, suffix them with the expression index to guarantee uniqueness
Example fix
// before select new map(a.id as id, b.id as id) from A a join a.b b // after select new map(a.id as aId, b.id as bId) from A a join a.b b
Defensive patterns
Strategy: validation
Validate before calling
// Verify aliases are unique before building/running the query
Set<String> seen = new HashSet<>();
for (String arg : args.split(",")) {
String alias = arg.trim().replaceFirst("(?is).*\\bas\\s+", "").trim();
if (!seen.add(alias)) throw new IllegalArgumentException("Duplicate alias in new map(...): " + alias);
} Prevention
- When copy-pasting a select line into a map instantiation, change the alias first
- For generated HQL, derive aliases from expression + position (e.g. col_0, col_1)
- Code-review rule: map instantiations must have as many distinct aliases as arguments
When it happens
Trigger: `select new map(a.id as x, b.id as x) from A a join a.b b`; copy-pasting an alias when adding a new argument to a map instantiation; aliases generated in a loop in dynamic query building that collide.
Common situations: Refactoring a select list by duplicating a line and forgetting to change the alias; HQL built by string concatenation where a variable alias is reused; large map instantiations where duplicate aliases are easy to miss.
Related errors
- alias for Map dynamic instantiation argument cannot be null
- Map instantiation contained one or more arguments with no al
- Map instantiation has arguments with duplicate aliases [{}]
- Cannot instantiate class '{}' (it has no constructor with si
- Entity join treats can not be aliased
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/cb33336ce316d278.
Report an issue: GitHub.