Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Search using Hibernate criteria querry

 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Yes, that works below is my code example

Thanks to all in helping me to fix this.VIJAY
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for that, yes i had updated the same.

Cheers then.
Vijay Gadde
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic