{"record":{"id":"d8edbd4e7279eda6","repo":"hibernate/hibernate-orm","slug":"map-instantiation-has-arguments-with-duplicate-ali","errorCode":null,"errorMessage":"Map instantiation has arguments with duplicate aliases [{}]","messagePattern":"Map instantiation has arguments with duplicate aliases \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java","lineNumber":140,"sourceCode":"\t\t\tboolean areAllArgumentsAliased,\n\t\t\tboolean areAnyArgumentsAliased,\n\t\t\tList<String> duplicatedAliases,\n\t\t\tList<ArgumentReader<?>> argumentReaders,\n\t\t\tAssemblerCreationState creationState) {\n\n\t\tif ( nature == DynamicInstantiationNature.LIST ) {\n\t\t\tif ( LOG.isDebugEnabled() && areAnyArgumentsAliased ) {\n\t\t\t\tLOG.debug( \"One or more arguments for List dynamic instantiation (`new list(...)`) specified an alias; ignoring\" );\n\t\t\t}\n\t\t\treturn (DomainResultAssembler<R>)\n\t\t\t\t\tnew DynamicInstantiationAssemblerListImpl( (JavaType<List<?>>) javaType, argumentReaders );\n\t\t}\n\t\telse if ( nature == DynamicInstantiationNature.MAP ) {\n\t\t\tif ( ! areAllArgumentsAliased ) {\n\t\t\t\tthrow new IllegalStateException( \"Map instantiation contained one or more arguments with no alias\" );\n\t\t\t}\n\t\t\tif ( !duplicatedAliases.isEmpty() ) {\n\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\"Map instantiation has arguments with duplicate aliases [\"\n\t\t\t\t\t\t\t\t+ StringHelper.join( \",\", duplicatedAliases ) + \"]\"\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn (DomainResultAssembler<R>)\n\t\t\t\t\tnew DynamicInstantiationAssemblerMapImpl( (JavaType<Map<?,?>>) javaType, argumentReaders );\n\t\t}\n\t\telse {\n\t\t\treturn assembler( areAllArgumentsAliased, duplicatedAliases, argumentReaders, creationState );\n\t\t}\n\t}\n\n\tprivate DomainResultAssembler<R> assembler(\n\t\t\tboolean areAllArgumentsAliased,\n\t\t\tList<String> duplicatedAliases,\n\t\t\tList<ArgumentReader<?>> argumentReaders,\n\t\t\tAssemblerCreationState creationState) {\n\t\t// find a constructor matching argument types","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java#L122-L158","documentation":"Thrown by DynamicInstantiationResultImpl.createResultAssembler when a `select new map(...)` query contains two or more arguments sharing the same alias. The message lists the offending aliases joined by commas. It fires at query-plan creation, before SQL execution, because duplicate keys cannot be represented in the resulting Map.","triggerScenarios":"`select new map(e.id as id, e.name as id) from Employee e`; joining several tables and using the same alias name (e.g. `as name`) for columns of different tables; alias placeholders like `as col` repeated in generated HQL.","commonSituations":"Copy-paste errors in hand-written HQL; alias collisions only noticed when the branch of code with that query first executes; schema-wide naming where many tables have identically named columns and aliases are reused.","solutions":["Rename the duplicate aliases so every argument has a unique key, e.g. `as customerId` and `as orderId`","Check the exception message - it names the exact duplicated aliases to fix","For generated queries, derive aliases from expression plus position to avoid collisions"],"exampleFix":"// before\nselect new map(o.id as id, c.id as id) from Order o join o.customer c\n// after\nselect new map(o.id as orderId, c.id as customerId) from Order o join o.customer c","handlingStrategy":"validation","validationCode":"// Fail fast on duplicate aliases before first execution\nSet<String> unique = new HashSet<>();\nboolean dup = !unique.addAll(aliasesOfNewMapArguments(hql));\nif (dup) throw new IllegalArgumentException(\"Duplicate aliases: \" + aliasesOfNewMapArguments(hql).stream().filter(a -> Collections.frequency(aliasesOfNewMapArguments(hql), a) > 1).toList());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the exception message - it lists the exact duplicated aliases","Namespace aliases by table prefix (orderId, customerId) instead of generic names (id, id)","Add a lint-style unit test for generated HQL asserting alias uniqueness"],"tags":["hql","dynamic-instantiation","map","duplicate-alias","query-plan"],"backgroundTag":"hql-dynamic-instantiation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}