我一直试图让 JDO 处理父/子关系,但我没有取得多大成功。使用此处所示的关系设置和此处所示的查询,我希望能够将孩子链接到父母,然后能够查询给定父母的所有孩子。不幸的是,我似乎没有正确地询问孩子们。我不断收到错误:
Class Parent for query has not been resolved. Check the query and any imports/aliases specification
这是我的代码的样子。首先是父类:
@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;
//...
}
儿童类:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Child
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private Parent parent;
@Persistent
private String name;
//...
}
最后,我尝试的查询看起来像这样:
Query q = pm.newQuery(Child.class);
q.setFilter("parent = parentParam");
q.declareParameters("Parent parentParam");
@SuppressWarnings("unchecked")
List<Child> childList = (List<Child>) q.execute(someParent);
有什么建议我可能做错了吗?非常感谢!