Reputation: 11
I've seen many examples but none seem to work for my issue. I'm using JDO in GAE (Java). I'm not geting any error messages. I'm just not getting a result when I know there should be or else the result matches objects with an empty List for dispatchId. Any help would be greatly appreciated!
Here's my relevant class code:
public class Department {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
...
// a list of codes that a department might be identified by
@Persistent
private List<String> dispatchId;
}
I'm trying to find a Department whose dispatchId List contains a specific dispatchId code. My Java servlet code is:
String dispatchId = "1353000"; // may contain letters and/or numbers
Query q = pm.newQuery(Department.class, ":dispatchId.contains(dispatchId)");
@SuppressWarnings("unchecked")
List<Department> depts = (List<Department>) q.execute(dispatchId);
In the GAE Datastore viewer (live on GAE) the dispatchId field for my test department looks like this (in case this helps):
[u'1353000', u'0566940', u'0566936', u'1368496']
Thanks again for any input... John
Upvotes: 0
Views: 241
Reputation: 91
Hello did you still looking for the answer?
Here is a solution for it:
String dispatchId = "someId";
Query query = pm.newQuery(Department.class);
query.setFilter("dispatchId == '"+ dispatchId + "'");
List<Department> depts = (List<Department>) query.execute();
Here you would need a single quote to enclose the parameter.
Upvotes: 3