• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Search using Criteria with OR condition.

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Yes that work I had used like below

Thanks for all that, vijay
reply
    Bookmark Topic Watch Topic
  • New Topic