Home » Support » Forum » selecting objects that have a particular key/value in persistant HashMap

selecting objects that have a particular key/value in persistant HashMap

#1

Hi,

First post here and exploring ObjectDB.  I have an class Person which has a HashMap<String, String> called 'pMap' as a persistable field.  I am able to create Person objects and persist them as expected.

However, am I able to search the HashMap field using JPA?  For example, lets assume that the pMap field of some Person objects has the key/value pair "location'/'California'.  Can I create a JPA query that selects such objects?  Something like the following (but clearly does not work) :  SELECT p FROM Person p where p.pMap['location']='California'

Any thoughts?  Thanks,

-Adam

 

#2

Please try the following query:

SELECT p FROM Person p WHERE p.pMap.get('location') = 'California'

This is not a valid JPQL query but an extension that ObjectDB should support.

If you need a more efficient solution (using an index), please look at this forum thread.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

that did the trick.


Post Reply

To post a reply and/or subscribe to update notifications - please login