-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Collection query help
PostPosted: Mon Sep 11, 2006 12:08 pm 
Newbie

Joined: Mon Sep 11, 2006 12:02 pm
Posts: 1
I am having difficulty constructing a Hibernate query, and would like some help if possible.

I have a class UserProfileRecordImpl that contains user profile information in a table profile_tbl. I also have a class KeywordRecordImpl that contains keywords in a table keyword_tbl. I've created a many-to-many association using a join table profile_keyword_tbl that allows users to enter keywords describing their profile. The association works fine, and I am able to create user profiles with keywords without any problem.

The query I would like to create, however, is one that would allow me to locate user profiles that contain some or all of the keywords I pass in. For example:

I have a user A with keyword "keyword_a", a user B with "keyword_b", and a user C with keywords "keyword_a" and "keyword_b". When I query for users with keyword "keyword_a" I would like to receive both user A and user C. When I query for users with both "keyword_a" and "keyword_b" I would like to receive ONLY user C.

The query I have thus far looks like this:

SELECT DISTINCT p FROM UserProfileRecordImpl p JOIN p.keywordRecords AS k"
+ " WHERE k.keyword IN (:keywordList)

where keywordList is a simple ArrayList containing the keywords I'm searching for. When I run my first query, it returns user A as expected. However, when I run my second query, I receive all 3 years. The query is essentially performing an "OR" for the keywords, instead of an "AND".

Can anyone tell me how I can write a query that lets me search for users that have ALL of the keywords I specify? Thanks much in advance!!

Steve Nakhla


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.