JDO - Querying/linking child by parent (Google App Engine)?

别来无恙 提交于 2020-01-07 04:51:09

问题


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:


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.



来源:https://stackoverflow.com/questions/16490293/jdo-querying-linking-child-by-parent-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!