Hi,
If I have an owned one-to-many relationship, the parent object
reference in the child is always null.
My code looks something like this:
@PersistenceCapable
public class Parent {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@Persistent(mappedBy="parent", defaultFetchGroup="true")
private List<Child> children = new LinkedList<Child>();
public List<Child> getChildren() {
return children;
}
public void addChild(Child child) {
child.setParent(this);
children.add(child);
}
}
@PersistenceCapable
public class Child {
@Persistent
private Parent parent;
@Persistent
private String field;
public Child(String field) {
this.field = field;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
With the code as above, I create an entity and persist it:
Parent parent = new Parent();
parent.addChild(new Child("foo"));
parent.addChild(new Child("bar"));
parent.addChild(new Child("baz"));
persistenceManager.makePersistent(parent);
When I read the Parent object back from the data store, I'm
able to traverse the list e.g.:
for (Child child : parent.getChildren()) {
out.println(child.getField());
}
produces
foo
bar
baz
However, the parent object reference as specified in the
mappedBy attribute on Parent.children is always null. So
e.g.:
for (Child child : parent.getChildren()) {
out.println(child.getParent());
}
produces
null
null
null
Am I doing something wrong?
-ian
--
Ian Murdock
http://ianmurdock.com/
"Don't look back--something might be gaining on you." --Satchel Paige
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.