CriteriaQuery<Video> criteria = cb.createQuery(Video.class);
var root = criteria.from(Video.class);
root.fetch("channel", JoinType.RIGHT);
var subquery = criteria.subquery(User.class);
var subroot = subquery.from(User.class);
subquery.select(subroot.get("subscribed_ids"))
.where(cb.equal(subroot.get("id"), user.getId()));
criteria.select(root)
.where(
root.get("channel").in(subquery)
)
.orderBy(cb.desc(root.get("uploaded")));
Stacktrace:
java.lang.IllegalArgumentException: Can't compare test expression of type [Channel] with element of type [User]
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.assertComparable(SqmCriteriaNodeBuilder.java:2098)
at org.hibernate.query.sqm.tree.predicate.SqmInListPredicate.implyListElementType(SqmInListPredicate.java:138)
at org.hibernate.query.sqm.tree.predicate.SqmInListPredicate.<init>(SqmInListPredicate.java:60)
at org.hibernate.query.sqm.tree.predicate.SqmInListPredicate.<init>(SqmInListPredicate.java:47)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.in(SqmCriteriaNodeBuilder.java:2618)
at org.hibernate.query.sqm.tree.expression.AbstractSqmExpression.in(AbstractSqmExpression.java:124)
at org.hibernate.query.sqm.tree.expression.AbstractSqmExpression.in(AbstractSqmExpression.java:31)
at me.kavin.piped.server.handlers.auth.FeedHandlers.feedResponse(FeedHandlers.java:119)
I’m facing a similar issue, but we are using specifications (Spring boot, the code was working prior to upgrading but not anymore. I think, the solution above is relevant but not sure how to rewrite it to make it work. Below is how it is
Can't compare test expression of type [BasicSqmPathSource(id : UUID)] with element of type [RecognitionRecipientEntity]
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.assertComparable(SqmCriteriaNodeBuilder.java:2102)
at org.hibernate.query.sqm.tree.predicate.SqmInListPredicate.implyListElementType(SqmInListPredicate.java:138)
Yup - I was just able to get it done, and yes your solution is inline with that.
I really appreciate your response, it give me confirmation of what I did.