JDO - Querying/linking child by parent (Google App

2019-09-18 16:28发布

I've been trying to get JDO working with parent/child relationships, but I'm not having much success. Using the relationship setup as seen here and queries as seen here, I want to be able to link a child to a parent, then be able to query for all children of a given parent. Unfortunately, I don't seem to be querying the children correctly. I keep getting the error:

 Class Parent for query has not been resolved. Check the query and any imports/aliases specification

Here's what my code looks like. First the Parent class:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Parent
{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @SuppressWarnings("unused")
    @Persistent(mappedBy = "parent")
    private ArrayList<Child> children;
    @Persistent
    private String name;

    //...
}

The Child class:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Child
{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private Parent parent;
    @Persistent
    private String name;

    //...
}

Lastly, my attempted query looks something like this:

Query q = pm.newQuery(Child.class);
q.setFilter("parent = parentParam");
q.declareParameters("Parent parentParam");
@SuppressWarnings("unchecked")
List<Child> childList = (List<Child>) q.execute(someParent);

Any suggestion what I might be doing wrong? Thank you much!

1条回答
Fickle 薄情
2楼-- · 2019-09-18 16:59

So define the package of "Parent" in the declareParameters call. It isn't in the root package is it? And JDOQL does not allow assignment "=", that should be "==" ... like in Java, because JDOQL uses Java syntax.

查看更多
登录 后发表回答