-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using criteria.add with "OR" instead of "AND&
PostPosted: Tue Nov 08, 2005 5:53 pm 
Newbie

Joined: Fri Dec 17, 2004 12:54 pm
Posts: 13
Hi,
I'm trying to use criteria.add to add expressions that are grouped together by the sql "or" instead of "and"

for example

criteria.add(Expression.like("field1","value1"));
criteria.add(Expression.like("field2","value1"));

would generate sql like

select * from ... WHERE field1='value1' OR field2="value1"

and not

select * from ... WHERE field1='value1' AND field2="value1"

Does anyone know how to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:01 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Restrictions.or(Restrictions.eq(), Restrictions.eq())

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:21 pm 
Newbie

Joined: Fri Dec 17, 2004 12:54 pm
Posts: 13
kochcp wrote:
Restrictions.or(Restrictions.eq(), Restrictions.eq())


Thanks for the tip.
Although I forgot to mention in my first post that I will have multiple "OR" conditions not just two. Could you give me an example how I would test test for say 3 conditions that are grouped by the sql "OR".

I'm a little stuck because it seems the Restrictions.or() method only lets you add 2 expressions (not a list) in its params.

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:27 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
gigantic method chain outta do it :)

restrictions.or(restrictions.or(eq,eq),restrictions.or(eq,eq))

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:55 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Take a look at Disjunction.

Disjunction.add(Exp1).add(Exp2).add(Exp3).....add(ExpN)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.