-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Error ORA-01795 "maximum number of expressions in a list is
PostPosted: Mon Apr 14, 2014 5:41 pm 
Newbie

Joined: Tue Dec 04, 2012 9:24 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: Error ORA-01795 "maximum number of expressions in a list is
PostPosted: Tue Apr 15, 2014 10:45 pm 
Newbie

Joined: Mon Apr 14, 2014 11:03 am
Posts: 8
Location: Orlando, FL
Have you tried wrapping all of the Criterion in a disjunction?

Code:
    * Group expressions together in a single disjunction (A or B or C...).
    *
    * This form creates an empty disjunction.  See {@link Disjunction#add(Criterion)}
    *
    * @return Conjunction
    */
   public static Disjunction disjunction() {
      return new Disjunction();
   }


I think it's a little suspect that you are hitting the 1000 limit using static values, however. Where are these values coming from? Is it possible to just use a DetachedCriteria with a projection of the value and use the Subqueries.propertyIn(String, DetachedCriteria) method?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.