PostgreSQL 和 Hibernate java.io.IOException:试图将超出范围的整数作为 2 字节值发送

Ром*_*нко 12 postgresql hibernate exception ioexception

我有休眠查询:

getSession()                     
        .createQuery("from Entity where id in :ids") 
        .setParameterList("ids", ids)
        .list();
Run Code Online (Sandbox Code Playgroud)

其中 ids 是 Collection id,可以包含很多 id。目前,当集合非常大时,我遇到了异常: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value 我听说 postgre 有一些问题。但是我找不到如何在 hql 上重写它的解决方案。

小智 26

发生异常的原因是 PostgreSQL 限制每个语句 32767 个绑定变量。作为一种可能的解决方法,尝试将大型查询拆分为较小的查询。


小智 -6

尝试在 周围添加括号:ids,即:

"from Entity where id in (:ids)"
Run Code Online (Sandbox Code Playgroud)