I'm trying to construct a JDOQL query (using datanucleus) that will search for matches of a parent class based on criteria in an owned one-to-many child class. The query looks like this:
Query lQ = lPm.newQuery("select from "+Module.class.getName()+
" where moduleMappings.contains(m)" +
" && showNameParam.matches(m.criteria.trim())");
lQ.declareVariables(ModuleMapping.class.getName()+" m");
lQ.declareParameters("String showNameParam");
lRet = (List<Module>) lQ.execute("StarTrek");
My data set looks something like this:
- Module[1]
- ModuleMapping[1]: criteria=".*"
- Module[2]
- ModuleMapping[1]: criteria=".*StarTrek.*"
- ModuleMapping[2]: criteria=".*StarWars.*"
The query never matches on anything! However, if I replace the argument to the matches
JDOQL method with a literal:
Query lQ = lPm.newQuery("select from "+Module.class.getName()+
" where moduleMappings.contains(m)" +
" && showNameParam.matches('.*StarTrek.*')");
Things will work for that single example, and my query will find Module[2]. What am I missing? Am I not allowed to use the contents of a mapped field as the argument to a JDOQL method? Do I need to escape things in some way?
Dave