-->
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: I don't know how to nest multiple OR
PostPosted: Mon Aug 06, 2007 4:46 am 
Newbie

Joined: Mon Aug 06, 2007 4:36 am
Posts: 1
Please somebody gimme the hint on how to convert this:

select * from table1

where criteria1 = value1 AND (criteria2 = value2 OR criteria3 = value3 OR..........OR criteriaN = valueN)

to Expression.or statement.

I take a look at API and it allows only a pair of two Expressions to be OR.



Many thnx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 5:08 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
What version of hibernate are you using? Expression is "semi-deprecated" in v3.2+

Use disjunction from Restrictions:

e.g.
Code:
Criteria c = session.createCriteria(Table1.class)
  .add(Restrictions.and(
    Restrictions.eq("criteria1", "value1"),
    Restrictions.disjunction()
      .add(Restrictions.eq("criteria2", "value2"))
      .add(Restrictions.eq("criteria3", "value3"))
      .add(Restrictions.eq("criteria4", "value4"))
      .add(Restrictions.eq("criteriaN", "valueN"))));


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.