File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Search using Criteria with OR condition. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Search using Criteria with OR condition." Watch "Hibernate Search using Criteria with OR condition." New topic
Author

Hibernate Search using Criteria with OR condition.

Vijay Gadde
Ranch Hand

Joined: Sep 30, 2008
Posts: 54
Hi, I need to write a dynamic search querry in my Hibernate application.

For the same I am using this Criteria API to build the querry dynamically bellow is code

When I run this querry, the querry its generating with AND conditions like below

as I mentioned in double quotes its using AND condition, but I want to use OR condition can some help to how can i do this.

Thanks in advance,VIJAY


Vijay Gadde
Coming together is a beginning. Keeping together is progress.. Working together is success........
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
to do a OR with the criteria API you can use

Restrictions.or(criterion1,criterion2)


SCJP 5 , SCWCD 5, SCEA 5
Vijay Gadde
Ranch Hand

Joined: Sep 30, 2008
Posts: 54
Thanks for that quick reply, I got big confusion with this Restrictions.OR(Criterian1, Criterian2).

If I will get 5 differnet integer values, so its like
select * from USERS where
user_name like 'vij%' or
type=1 or
typ=2 or
type=3;

But this Restrictions is like between two values only, but I need to make it for all the values dynamically could you please help how to fix this..!
Thanks,VIJAY
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

For that particular query, qould you not be better using an InExpression? Is that not logically the same?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vijay Gadde
Ranch Hand

Joined: Sep 30, 2008
Posts: 54
Hi Paul,
Yes that work I had used like below

Thanks for all that, vijay
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate Search using Criteria with OR condition.