30

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.

4 Answers4

61

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.

Andrey Dolgikh
  • 861
  • 8
  • 7
0

In newer PostgreSQL driver 42.4.0 you can now pass up to 65,535 records.

fix: queries with up to 65535 (inclusive) parameters are supported now (previous limit was 32767) PR #2525, Issue #1311

Source: https://jdbc.postgresql.org/changelogs/2022-06-09-42.4.0-release/

Alex
  • 1,986
  • 22
  • 23
-2

If you don't want split your large query into smaller ones, you may use JDBC: ResultSet executeQuery()

Stan
  • 1
  • 1
-6

Try adding parenthesis around :ids, i.e.:

"from Entity where id in (:ids)"
Pang
  • 9,564
  • 146
  • 81
  • 122