• 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

Search using Hibernate criteria querry

 
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 There,

I am trying to build Search option on a SINGLE table USER_PROFILES in my application.

This search plan was, we are going get FirstName,LastName,EmailAddress and an arry of UserType's. We need to search
" (FirstName AND LastName AND EmailAddress and 'usertype1') OR
(FirstName AND LastName AND EmailAddress and 'usertype2') OR
..... SO ON
"
Bellow is the example querry:

Bellow is my Hydernate code I am trying to build for this

I know, I was trying to build this using this
Criterion u_type = Restrictions.like("siteId",""+searchRequestData.getSiteId())
For this Restrictions, every time we need to pass two different arguments, so I understand its between two values not for arguments.
So I struggling to build this and finding how to do this.
Please help me, thanks,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
I think your query would be more simple if you express it like this

SELECT * FROM USER_PROFILE where
(
(FirstName='Geo' AND LastName='king' AND EmailAddress='Geor.King@test.com')
and
(and usertype in (1,2,3))

in hibernate roughly you would have

criteria.add(Expression.like("FirstName","%"+FirstName+"%");
criteria.add(Expression.like("LastName","%"+LastName+"%");
criteria.add(Expression.like("EmailAddress","%"+EmailAddress+"%");
criteria.add(Restriction.in("usertype ",myArrayListWithValues);
 
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
Yes, that works below is my code example

Thanks to all in helping me to fix this.VIJAY
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
VIJAY can you please adjust your display name so that it doe not contain all upper case letters, maybe Vijay Gadde.

Thanks.
 
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, yes i had updated the same.

Cheers then.
Vijay Gadde
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic