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?