{"record":{"id":"aecf81e1133551da","repo":"hibernate/hibernate-orm","slug":"unexpected-collection-reference-collectionrefere","errorCode":null,"errorMessage":"Unexpected collection reference: {collectionReferenceCtx.getText()}","messagePattern":"Unexpected collection reference: (.+?)","errorType":"exception","errorClass":"ParsingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":5314,"sourceCode":"\t\tfor ( int i = implicitJoinPaths.size() - 1; i >= 0; i-- ) {\n\t\t\tjoinBase = joinBase.join( implicitJoinPaths.get( i ) );\n\t\t}\n\t\tfinal var collectionJoin = joinBase.join( pluralAttributePath.getNavigablePath().getLocalName() );\n\t\tfromClause.addRoot( correlation.getCorrelatedRoot() );\n\t\tif ( collectionReferenceCtx == null ) {\n\t\t\tfinal var literal = new SqmLiteral<>(\n\t\t\t\t\t1,\n\t\t\t\t\tnodeBuilder().getIntegerType(),\n\t\t\t\t\tnodeBuilder()\n\t\t\t);\n\t\t\tsubQuery.applyInferableType( literal.getNodeType() );\n\t\t\tselectClause.setSelection( literal );\n\t\t}\n\t\telse {\n\t\t\tfinal String partName = switch ( collectionReferenceCtx.getSymbol().getType() ) {\n\t\t\t\tcase HqlParser.ELEMENTS -> CollectionPart.Nature.ELEMENT.getName();\n\t\t\t\tcase HqlParser.INDICES -> CollectionPart.Nature.INDEX.getName();\n\t\t\t\tdefault -> throw new ParsingException( \"Unexpected collection reference: \"\n\t\t\t\t\t\t+ collectionReferenceCtx.getText() );\n\t\t\t};\n\t\t\tfinal var path = collectionJoin.resolvePathPart( partName, true, this );\n\t\t\tsubQuery.applyInferableType( path.getNodeType() );\n\t\t\tselectClause.setSelection( path );\n\t\t}\n\t\tfinal var querySpec = subQuery.getQuerySpec();\n\t\tquerySpec.setFromClause( fromClause );\n\t\tquerySpec.setSelectClause( selectClause );\n\t\treturn subQuery;\n\t}\n\n\tprivate SqmPredicate getFilterExpression(ParseTree functionCtx) {\n\t\tfinal int childCount = functionCtx.getChildCount();\n\t\tfor ( int i = childCount - 2; i < childCount; i++ ) {\n\t\t\tfinal var child = functionCtx.getChild( i );\n\t\t\tif ( child instanceof HqlParser.FilterClauseContext ) {\n\t\t\t\treturn (SqmPredicate) child.getChild( 2 ).getChild( 1 ).accept( this );","sourceCodeStart":5296,"sourceCodeEnd":5332,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L5296-L5332","documentation":"Error \"Unexpected collection reference: {collectionReferenceCtx.getText()}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate query API is violated: Unexpected collection reference: <value>","commonSituations":"Application code or configuration calls the query API in a way that violates its documented contract; the interpolated values in the message identify the offending input.","solutions":["The collection reference in the query is not valid in this context. Check the HQL syntax around the collection reference and use a proper collection path or join."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}