【发布时间】:2022-09-29 22:25:34
【问题描述】:
无论如何我可以使用 JPQL 的SIZE 函数在WHERE 子句中绑定变量吗?
像这样的东西:
and (size(:distributor_ids) = 0 or d.id in (:distributor_ids))
Hibernate 抛出以下异常:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unexpected expression ? found for collection function size
我的查询很大,但是这个 AND 子句相当简单:如果列表为空,则检索所有内容;如果列表不为空,则检索所有满足d.id IN (:distributor_ids) 的行。
有没有办法做到这一点?