This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Search using Criteria with OR condition.

 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to do a OR with the criteria API you can use

Restrictions.or(criterion1,criterion2)
 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that particular query, qould you not be better using an InExpression? Is that not logically the same?
 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Yes that work I had used like below

Thanks for all that, vijay
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic