views:

41

answers:

1

Hi,

I'm quite new to JDO and wanted to ask if it is possible to filter using complex objects. I know that you can do something like this:

Query q = pm.newQuery(MyClass.class, "field1 < value");
q.declareParameters("int value");
List results = q.execute(205);
Iterator iter = results.iterator();

But assume I have the following situation:

@PersistenceCapable(...)
class ParentObj{
   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   String id;
   ...
   @Persistent
   ChildObj child;
}

@PersistenceCapable(...)
class ChildObj{
   @Persistent
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   String id;

   ...
}

Now assume I want to filter all ParentObj objects that have some given ChildObj. I have

public List<ParentObj> getAllParentObjBy(ChildObj child){
   PersistenceManager pm = ...
   Query query = pm.newQuery(ParentObj.class, "child = childVal");
   query.declareParameters("ChildObj childVal");

   Collection result = (Collection)query.execute(child);
   //???

   return result;
}

This is very pseudocode, but I hope the idea is clear. Can I somehow use the Query object like in the first example but in this case with the child instance?

+1  A: 

You can definitely do "child == childVal" (i.e equality) ... since you can in Java.

You cannot do assignment ("=").

DataNucleus
thanks for your info. I did everything right, but I guess this is the problem: http://code.google.com/appengine/docs/java/datastore/usingjdo.html#Unsupported_Features_of_JDOJoins aren't supported.
Juri