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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Search using Hibernate criteria querry" Watch "Search using Hibernate criteria querry" New topic

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

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

in hibernate roughly you would have

criteria.add(Restriction.in("usertype ",myArrayListWithValues);

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

Joined: Jun 06, 2007
Posts: 2716

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


|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
Similar Threads
Hibernate Search using Criteria with OR condition.
JSP makes me headache
Criteria on joining fails
Pesudo coding
hibernate createCriteria issue