小编gam*_* wu的帖子

如何检查hql中的collection参数是否为null?

那么如何检查hql中的集合是否为null?简单的例子:

select * from Book book where title in (:titles)
Run Code Online (Sandbox Code Playgroud)

因此,如果标题是单一的可用,我可以做到

select * from Book book where (:titles is null or title in (:titles))
Run Code Online (Sandbox Code Playgroud)

但是如果title是列表/集合呢?

select * from Book book where (:titles is null or title in (:titles))
Run Code Online (Sandbox Code Playgroud)

如果title是一个列表,这将不起作用.在强烈搜索之后,我尝试了空,大小和存在函数,我也试过(:titles)是null选项.

以上都不是.我知道有一种硬编码方式,即编写不同的查询取决于标题列表的状态,如果它是null,一个查询,如果它是null,则另一个查询.但这会产生很多类似的hql查询,只有很小的改动.我的用例中还有更多的列表需要考虑,因此不太理想.

我的问题是甚至可以直接在hql中进行检查吗?

hibernate hql

7
推荐指数
1
解决办法
590
查看次数

标签 统计

hibernate ×1

hql ×1