JDO - 父项查询/链接子项(Google App Engine)? [英] JDO - Querying/linking child by parent (Google App Engine)?

查看:159
本文介绍了JDO - 父项查询/链接子项(Google App Engine)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让JDO与父母/孩子的关系一起工作,但我没有取得太大的成功。使用此处的关系设置和查看这里,我希望能够将孩子链接到父母,然后能够查询给定父母的所有孩子。不幸的是,我似乎没有正确地查询孩子。我不断收到错误信息:

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;

    //...
}

Child类:

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!

推荐答案

因此,在declareParameters调用中定义Parent包。它不在根包里吗? JDOQL不允许赋值=,应该是==......就像在Java中一样,因为JDOQL使用Java语法。

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.

这篇关于JDO - 父项查询/链接子项(Google App Engine)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆