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.  [ 2 posts ] 
Author Message
 Post subject: AND join not working in set property
PostPosted: Thu Jul 23, 2009 5:07 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
I have a complicated query which I'm building using Criteria/Restrictions etc

The Hibernate object hierarchy is like...
Code:
      Expert
          |--- ToolExpertise <set>
                      |--- ToolExpertise
                                   |--- Tool
                                   |--- Competence

An expert has expertise in one of more tools (a set property at the Expert level), and the ToolExpertise has two class instance properties: 'Tool' (i.e. Excel, Eclipse), and 'Competence' (beginner/average/expert). For example: 'Fred' is an expert who has two ToolExpertise instances: Eclipse/Average and Excel/Expert.

The query is designed to return a list of all experts that match the declared tool/competence parameters, one which there can be one or more pairs.

I use the Criteria methods to map a sub criteria to the ToolExpertise set and alias mappings from that to Tool and Competence. I then use the alias names to build the Restrictions.

I have a problem in trying to search for multiple Tool/Competence pairs. For instance, if I search for...
Eclipse/Average OR Excel/Expert
.... then it brings back the right set of Experts. However if I search for...
Eclipse/Average AND Excel/Expert
... then I get nothing back, even though I know there is one matching test record that exists.

I suppose in a way this boils down to a logical table like..
Code:
Expert   Tool
  A     1
  A           2
  B           1
  B           3
  C          1
  C          4

Hence, from the example table above I want to search for any expert that is linked to both Tool value '1' and '2', i.e. expert 'A'

Any ideas?


Top
 Profile  
 
 Post subject: Re: AND join not working in set property
PostPosted: Thu Jul 23, 2009 8:04 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
I've worked out how to build a SQL version of the required query, like...
Code:
SELECT Expert
FROM mytable
WHERE Tool IN (1,2)
GROUP BY Expert
HAVING COUNT(*) = 2

Any suggestions for how I translate this into 'Projections' based extension to my Criteria based query?


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

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.