hibernatehql

Maximum list size that can be passed


There is nothing wrong with the following code. It works fine. I just have a question about passing lists as parameters in HQL. I am using the IN clause in an HQL query like this:

AND l.creditGlCode IN (?3)

Then setting the parameter like this:

aQuery.setParameter(3, glCodes);

The HashSet glcodes contains strings. What is the maximum size that glcodes can be when passing it as a parameter in HQL? I remember reading somewhere that there is a limit but through countless number of google searches I can't find the answer.


Solution

  • I hope this will help. https://hibernate.onjira.com/browse/HHH-1123


    The original answer referenced content that does not exist anymore. The content pasted below was copied via the Wayback Machine (and is what the original link was referencing):

    enter image description here

    The number of elements that we can put in a "in" expression is limited to a certain amount (1000 for Oracle, for instance). When creating a criteria query, the org.hibernate.criterion.InExpression class should split the expression into several smaller ones.

    Attached is a patch which splits the expression by slices of 500 elements. For example, if we have 1001 elements to put in the "in" expression, the result would be : (entity.field in (?, ?, ?...) or entity.field in (?, ?, ?...) or entity.field in )

    The surrounding parantheses are useful to avoid problems with other conditions (a "and" condition taking over the one of the "or" conditions).