{"record":{"id":"d4ecc9eaf21ed5e4","repo":"hibernate/hibernate-orm","slug":"selection-item-in-a-multi-select-cannot-contain-co","errorCode":null,"errorMessage":"Selection item in a multi-select cannot contain compound array-valued elements","messagePattern":"Selection item in a multi-select cannot contain compound array-valued elements","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java","lineNumber":1334,"sourceCode":"\t/**\n\t * Check the arguments of {@link jakarta.persistence.criteria.CriteriaBuilder#array},\n\t * {@link jakarta.persistence.criteria.CriteriaBuilder#construct}, or\n\t * {@link jakarta.persistence.criteria.CriteriaBuilder#tuple}.\n\t *\n\t * @param selections The selection varargs to check\n\t *\n\t * @throws IllegalArgumentException If the selection items are not valid per\n\t *         according to {@linkplain CriteriaQuery#multiselect this documentation}.\n\t *         <i>&quot;An argument to the multiselect method must not be a tuple-\n\t *         or array-valued compound selection item.&quot;</i>\n\t */\n\tprivate void checkMultiselect(List<? extends Selection<?>> selections) {\n\t\tfinal HashSet<String> aliases = new HashSet<>( determineProperSizing( selections.size() ) );\n\t\tfor ( var selection : selections ) {\n\t\t\tif ( selection.isCompoundSelection() ) {\n\t\t\t\tfinal Class<?> javaType = selection.getJavaType();\n\t\t\t\tif ( javaType.isArray() ) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Selection item in a multi-select cannot contain compound array-valued elements\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif ( Tuple.class.isAssignableFrom( javaType ) ) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Selection item in a multi-select cannot contain compound tuple-valued elements\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinal String alias = selection.getAlias();\n\t\t\tif ( StringHelper.isNotEmpty( alias ) && !aliases.add( alias ) ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Multi-select expressions have duplicate alias '\" + alias + \"'\" );\n\t\t\t}\n\t\t}\n\t}\n\n\t@Nonnull\n\t@Override","sourceCodeStart":1316,"sourceCodeEnd":1352,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java#L1316-L1352","documentation":"CriteriaQuery.multiselect validates each selection item per the JPA spec: an argument to multiselect must not itself be a tuple- or array-valued compound selection. checkMultiselect throws IllegalArgumentException when a compound selection item (built by cb.array(...)) whose Java type is an array is nested inside multiselect — the resulting row shape would be ambiguous.","triggerScenarios":"query.multiselect(cb.array(root.get(\"a\"), root.get(\"b\")), root.get(\"c\")) — cb.array produces a compound selection typed Object[], which is rejected; also passing a selection produced by another array() call (e.g. a shared helper returning Selection<Object[]>) into multiselect.","commonSituations":"Copy-pasting an existing 'select as array' helper into a multiselect-based projection; refactoring query.select(cb.array(...)) into multiselect(...) without flattening; building dynamic column lists where an array group is appended as one item.","solutions":["Flatten: pass the individual expressions to multiselect (multiselect(a, b, c)) instead of nesting array(...).","If you really want Object[] rows, use query.select(cb.array(...)) once — not multiselect.","For typed wrappers use multiselect with a construct()/tuple only at the top level, never nested."],"exampleFix":"// before\nquery.multiselect(cb.array(root.get(\"sku\"), root.get(\"name\")), root.get(\"qty\"));\n// -> Selection item in a multi-select cannot contain compound array-valued elements\n\n// after\nquery.multiselect(root.get(\"sku\"), root.get(\"name\"), root.get(\"qty\"));","handlingStrategy":"validation","validationCode":"boolean validMultiselect(List<? extends Selection<?>> items) {\n    for (Selection<?> s : items) {\n        if (s.isCompoundSelection() && s.getJavaType() != null && s.getJavaType().isArray()) return false;\n    }\n    return true;\n}\nif (!validMultiselect(selections)) throw new IllegalArgumentException(\"flatten array() items before multiselect\");","typeGuard":"static boolean isCompoundArrayItem(Selection<?> s) {\n    return s.isCompoundSelection() && s.getJavaType() != null && s.getJavaType().isArray();\n}","tryCatchPattern":"try {\n    query.multiselect(items);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"array-valued\")) { /* flatten cb.array(...) items into individual expressions */ }\n    else throw e;\n}","preventionTips":["Treat multiselect arguments as a flat list of scalar/composite items; never nest array(...).","Use query.select(cb.array(...)) when Object[] rows are the goal.","Audit dynamic-projection helpers that append prebuilt Selection<Object[]> items."],"tags":["hibernate","criteria","multiselect","jpa","validation"],"backgroundTag":"invalid-multiselect-item","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}