PostgreSQL and Hibernate java.io.IOException: Tried to send an out-of-range integer as a 2-byte value

Роман Бондаренко picture Роман Бондаренко · Mar 14, 2018 · Viewed 7.6k times · Source

I have hibernate query:

getSession()                     
        .createQuery("from Entity where id in :ids") 
        .setParameterList("ids", ids)
        .list();

where ids is Collection ids, that can contain a lot of ids. Currently I got exception when collection is very large: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value I heard that postgre has some problem with it. But I can't find the solution how to rewrite it on hql.

Answer

Andrey Dolgikh picture Andrey Dolgikh · Sep 10, 2018

The exception occurs because of PostgreSQL's limit of 32767 bind variables per statement. As a possible workaround try to split your large query into smaller ones.