I am trying to build a subquery for a QueryDSL select that uses an exists clause in a BooleanExpression.
The data model is such that there are projects which contain a single media. Media can have many dimensions. I am looking to select projects that have certain dimensional data and am using a subquery to accomplish that.
The subquery looks like this:
QProject project = QProject.project;
QMedia media = QMedia.media;
Predicate subExpression = JPAExpressions.selectOne()
.from(media)
.innerJoin(media.dimensions)
.where(project.media.id.eq(media.id),
dimension.dimensionType.id.eq(Long.valueOf(inputDimensionType))).exists();
I store this as a predicate but, when I try to utilize it inside of a parent query I get an error: antlr.NoViableAltException: unexpected token: elements
The generated portion that is causing the error looks something like this (from the hibernate.hql.internal logs):
... and ((exists (select 1
from com.app.model.Media media
inner join elements(media.dimensions)
That is the error that happens when I plug it into a master query like this:
JPAQuery<ResponseCurve> query = new JPAQuery<>(this.entityManager);
query.select().from(project)
.where(project.state.eq(inputState))
.where(subExpression);