-->
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: Criteria API and the OR Expression
PostPosted: Tue Dec 21, 2004 2:44 pm 
Newbie

Joined: Tue Dec 21, 2004 2:28 pm
Posts: 2
Hello,

I'm using the Criteria API and i Need to produce such SQL

from Foo f where a=? and (b=? or b=? or b=? or b=?)

but i only managed to produce that
from Foo f where a=? and (((b=? or b=?) or b=?) or b=?)

Is it possible to limit the brackets ?
I'm also obliged to limit the size of my SQL so every 300 criterions, i create a new request.

Hibernate version: 2.1.7

Code between sessionFactory.openSession() and session.close():
Code:
      List criteriaList = new ArrayList();
      String a = "bar";
      int i = 0;
      for (Iterator iter = fooBCodes.iterator(); iter.hasNext(); i++) {
        String b = (String) iter.next();
        criterion = Expression.eq("b", b);
        if (currentCriterion == null) {
          crit = session.createCriteria(Foo.class);
          crit.add(Expression.eq("a", a));
          currentCriterion = criterion;
        } else {
          currentCriterion = Expression.or(currentCriterion, criterion);
        }
        if (i > 300) {
          i = 0;
          if (currentCriterion != null) {
            crit.add(currentCriterion);
          }
          criteriaList.add(crit);
          currentCriterion = null;
          crit = null;
        }
      }
      if (crit != null) {
        if (currentCriterion != null) {
          crit.add(currentCriterion);
        }
        criteriaList.add(crit);
      }



Top
 Profile  
 
 Post subject: Response to myself
PostPosted: Wed Dec 22, 2004 3:57 am 
Newbie

Joined: Tue Dec 21, 2004 2:28 pm
Posts: 2
If i had read the API correctly i would have noticed that, there is a disjonction method in the class Expression.


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.