hibernate/hibernate-orm · error · ParsingException
Unexpected collection reference: {collectionReferenceCtx.get
Error message
Unexpected collection reference: {collectionReferenceCtx.getText()} What it means
Error "Unexpected collection reference: {collectionReferenceCtx.getText()}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:5314
for ( int i = implicitJoinPaths.size() - 1; i >= 0; i-- ) {
joinBase = joinBase.join( implicitJoinPaths.get( i ) );
}
final var collectionJoin = joinBase.join( pluralAttributePath.getNavigablePath().getLocalName() );
fromClause.addRoot( correlation.getCorrelatedRoot() );
if ( collectionReferenceCtx == null ) {
final var literal = new SqmLiteral<>(
1,
nodeBuilder().getIntegerType(),
nodeBuilder()
);
subQuery.applyInferableType( literal.getNodeType() );
selectClause.setSelection( literal );
}
else {
final String partName = switch ( collectionReferenceCtx.getSymbol().getType() ) {
case HqlParser.ELEMENTS -> CollectionPart.Nature.ELEMENT.getName();
case HqlParser.INDICES -> CollectionPart.Nature.INDEX.getName();
default -> throw new ParsingException( "Unexpected collection reference: "
+ collectionReferenceCtx.getText() );
};
final var path = collectionJoin.resolvePathPart( partName, true, this );
subQuery.applyInferableType( path.getNodeType() );
selectClause.setSelection( path );
}
final var querySpec = subQuery.getQuerySpec();
querySpec.setFromClause( fromClause );
querySpec.setSelectClause( selectClause );
return subQuery;
}
private SqmPredicate getFilterExpression(ParseTree functionCtx) {
final int childCount = functionCtx.getChildCount();
for ( int i = childCount - 2; i < childCount; i++ ) {
final var child = functionCtx.getChild( i );
if ( child instanceof HqlParser.FilterClauseContext ) {
return (SqmPredicate) child.getChild( 2 ).getChild( 1 ).accept( this );View on GitHub (pinned to fad1729dce)
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.
When it happens
Trigger: A runtime precondition of the Hibernate query API is violated: Unexpected collection reference: <value>
Common situations: 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.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/aecf81e1133551da.
Report an issue: GitHub.