{"record":{"id":"94e412b884ecdcfa","repo":"hibernate/hibernate-orm","slug":"map-instantiation-contained-one-or-more-arguments","errorCode":null,"errorMessage":"Map instantiation contained one or more arguments with no alias","messagePattern":"Map instantiation contained one or more arguments with no alias","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java","lineNumber":137,"sourceCode":"\n\t@SuppressWarnings(\"unchecked\")\n\tprivate DomainResultAssembler<R> resolveAssembler(\n\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,","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java#L119-L155","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nList<Map<?,?>> rows = session.createQuery(\"select new map(e.id, e.name) from Employee e\", Map.class).getResultList();\n// after\nList<Map<?,?>> rows = session.createQuery(\"select new map(e.id as id, e.name as name) from Employee e\", Map.class).getResultList();","handlingStrategy":"validation","validationCode":"// With Criteria API, fail fast before execution if any selection lacks an alias\nList<Selection<?>> parts = cb.construct? null : null; // (illustrative)\nfor (Selection<?> s : compoundSelections) {\n    if (s.getAlias() == null) throw new IllegalStateException(\"Selection needs alias for map instantiation: \" + s);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hql","dynamic-instantiation","map","alias","illegal-state"],"backgroundTag":"hql-dynamic-instantiation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}