Quantcast
Channel: Java Programming Forum - Learn Java Programming - Hibernate
Viewing all articles
Browse latest Browse all 76

Error ORA-01795 "maximum number of expressions in a list is 1000"

$
0
0
Hi the team,

I'm facing a problem which cannot find its solution.
I have a query which must contain a big set of values, greater than 100.

With Java and Hibernate, if i want to filter my value, i have to do :

Code:

criteria.add(Restrictions.in(criteriaName, listOfValues);
But i get the error code ORA-01795 "maximum number of expressions in a list is 1000".
That's why i would like to make sub queries using the following code:
Code:

  int maxValues = 1;
    int nbValues = listOfValues.size();
 
    // Determine the number of sub lists to be created.
    int nbCriteria = (int) (nbValues / maxValues);
    nbCriteria = (nbCriteria * maxValues == nbValues) ? nbCriteria : nbCriteria + 1;
 
    // Create the sub lists related to the criteria.
    int startIndex = 0, stopIndex = startIndex + maxValues;
    for (int i = 0; i < nbCriteria; i++) {     
      if (stopIndex > nbValues) {
        stopIndex = nbValues;
      }   
      if (i == 0) {
        criteria.add(Restrictions.in(criteriaName, listOfValues.subList(startIndex, stopIndex)));       
      } else {
        criteria.add(Restrictions.or(Restrictions.in(criteriaName, listOfValues.subList(startIndex, stopIndex))));
      }
      startIndex += maxValues; 
      stopIndex += maxValues;
    }

Normally Hibernate should generate a query like :
Code:

...where criteriaName in (val1, ..., val100) OR criteriaName in (val101, ..., val200) ...)
But Hibernate replaces the key word OR by AND. And i got:
Code:

...where criteriaName in (val1, ..., val100) AND criteriaName in (val101, ..., val200) ...)
Can you please help me to find a solution ?

Regards,
berni.

Viewing all articles
Browse latest Browse all 76

Trending Articles