Hi, I am failing to retrieve child-objects in a one-to-many JDO relation in the datastore. The case is as follows;
I have two classes (Parent & Child, code-snippet below) with a defined one-to-many relation. It is no problem storing the structure with the 'store'-operation defined below. This is easily verified by web-browsing the datastore. However, when retrievning the parent-object from the datastore ('fetchParents'), the ''childs' attribute is always null. What must be done to (auto-)populate this attribute from the datastore? Also, the 'parent'-attribute of the Child-objects will also be null if they are fetched in a similar way. All clues appreciated... Lars - - - - - - - Code samples below - - - - - - @PersistenceCapable(identityType = IdentityType.APPLICATION) public class ParentDTO { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") private String encodedKey; @Persistent public String name; @Persistent(mappedBy="parent") public List<Child> childs; public ParentDTO() { } public void add(Child c) { if (childs == null) childs = new ArrayList<Child>(); kids.add(c); } } - - - - @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Child { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") public String encodedKey; @Persistent public String name; @Persistent public Parent parent; public Child() { } public String getEncodedKey() { return encodedKey; } } - - - - - Storing to datastore (works perfectly) public void store() { Parent p = new Parent(); p.navn = "nils"; Child c = new Child(); c.name = "jim"; p.add(c); c = new ChildDTO(); c.name = "anne"; p.add(c); PersistenceManager pm = PMF.get().getPersistenceManager(); try { pm.makePersistent(p); } catch (Exception ee) { res = ee.getMessage(); } finally { pm.close(); } } - - - - - - Fetching data (not working) public String fetchParents() { String res = ""; PersistenceManager pm = PMF.get().getPersistenceManager(); javax.jdo.Query query = pm.newQuery(Parent.class); List<Parent> parents = (List<Parent>) query.execute(); Iterator<Parent> iterF = parents.iterator(); while (iterF.hasNext()) { Parent f = iterF.next(); res = res + ":" + f.name; if (f.childs != null) { // this is the problem - 'this.childs' is always null Iterator<Child> iterI = f.childs.iterator(); while (iterI.hasNext()) { Child idto = iterI.next(); res = res + ">" + idto.name; } } } pm.close(); } --~--~---------~--~----~------------~-------~--~----~ 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 google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~----------~----~----~----~------~----~------~--~---