openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Knoche <kno...@MPA-Garching.MPG.DE>
Subject Querying for multiple key/value pairs within a map
Date Mon, 19 Sep 2011 09:03:02 GMT

I have a problem when querying for key/value of a map, where I 
understood the problem and also already found a solution, but the 
solution is not usable for me.

I have an object which contains a map with metadata and I want to query 
now for these objects which have a specific set (key/value) of metadata. 
I know that I have to specify the following query:

SELECT x from InitObject x JOIN x.metaDataset y WHERE KEY(y)='str' AND 

This works for exactly one key/value pair, but I need to query for 
several of these pairs. So my first try was to add another
AND KEY(y)='str3' AND VALUE(y)='str4'
which didn't return any result (which I can understand now).
After rewriting the query to the following:

SELECT x from InitObject x JOIN x.metaDataset y JOIN x.metaDataset z 
WHERE KEY(y)='str' AND VALUE(y)='str2' AND KEY(z)='str3' AND VALUE(z)='str4'

it worked as expected. But I don't like the idea of adding additional 
JOINs for every pair I want to query for, so my question is, if there is 
another way to do these queries since the number of pairs to query for 
can reach up to about 50.

Cheers and thanks in advance,

View raw message