-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Restrictions.or condition
PostPosted: Thu Feb 12, 2009 6:39 am 
Newbie

Joined: Wed May 24, 2006 5:47 pm
Posts: 14
Hi.

Im using this environment
Hibernate version: 3.2.6

I need to create a criteria with an OR condition; i must use the Restrictions.or method.
Now Let's image i'ld love to have this kind of query:

Code:
select * from person where name='tom' or name='john' or name='linda';


I can image a so structured code:

Code:
Criteria crit = session.createCriteria(Person.class);
crit.add( Restrictions.or( Property.forName( "name" ).eq("tom"), Property.forName( "name" ).eq("john") ) );
//How can i add the third OR condition?


In the example how can i add the third or condition?

As you can see it's very simple to add an OR condition when i have a even number of condition; how can handle the scenario where the condition number is odd?

Regards,
Angelo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 8:10 am 
Newbie

Joined: Tue Dec 04, 2007 10:20 am
Posts: 13
Work with the disjunction method in Criteria

Group expressions together in a single disjunction (A or B or C...)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 8:17 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Code:
crit.add(Restrictions.disjunction().add(Restrictions.eq("name", "A")).add(Restrictions.eq("name", "B")).add(Restrictions.eq("name", "C")));


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