wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Search using Hibernate criteria querry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Search using Hibernate criteria querry" Watch "Search using Hibernate criteria querry" New topic
Author

Search using Hibernate criteria querry

Vijay Gadde
Ranch Hand

Joined: Sep 30, 2008
Posts: 54
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


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
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);


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

Joined: Sep 30, 2008
Posts: 54
Yes, that works below is my code example

Thanks to all in helping me to fix this.VIJAY
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

VIJAY can you please adjust your display name so that it doe not contain all upper case letters, maybe Vijay Gadde.

Thanks.


SCJP, SCWCD.
|Asking Good Questions|
Vijay Gadde
Ranch Hand

Joined: Sep 30, 2008
Posts: 54
Thanks for that, yes i had updated the same.

Cheers then.
Vijay Gadde
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Search using Hibernate criteria querry