Hi all, perhaps I missed something or I'm only tired but I cannot make this simple update work. I just replace a child object with a new one but the update is simply not persisted. Hope you're more awake than me. Thanks Here's the snippet and my classes: ----------------- SNIPPET ------------------------------ public void test() { String parentId = "parent"; String childId_1 = "child-1"; String childId_2 = "child-2"; PersistenceManager pm = PMF.get().getPersistenceManager(); Parent parent = new Parent(); parent.setId(parentId); Child child = new Child(); child.setId(childId_1); child.setValue(100); parent.setChild(child); pm.makePersistent(parent); pm.close(); pm = PMF.get().getPersistenceManager(); String parentEncodedKey = KeyFactory.createKeyString(Parent.class.getSimpleName(), parentId); parent = pm.getObjectById(Parent.class, parentEncodedKey); assertEquals(100, parent.getChild().getValue()); child = new Child(); child.setId(childId_2); child.setValue(1000); parent.setChild(child); pm.makePersistent(parent); pm.close(); pm = PMF.get().getPersistenceManager(); parentEncodedKey = KeyFactory.createKeyString(Parent.class.getSimpleName(), parentId); parent = pm.getObjectById(Parent.class, parentEncodedKey); assertEquals(1000, parent.getChild().getValue()); pm.close(); } ----------------------------------------------- ---------------- PARENT ------------------------------- @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Parent implements Serializable { private static final long serialVersionUID = -3051163582728562957L; @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") protected String encodedKey; @Persistent @Extension(vendorName="datanucleus", key="gae.pk-name", value="true") private String id; @Persistent(defaultFetchGroup="true") @Element(dependent="true") private Child child; public String getEncodedKey() { return encodedKey; } public void setEncodedKey(String encodedKey) { this.encodedKey = encodedKey; } public String getId() { return id; } public void setId(String id) { this.id = id; } public Child getChild() { return child; } public void setChild(Child child) { this.child = child; } } ----------------------------------------------- ------------------- CHILD ---------------------------- @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Child implements Serializable { private static final long serialVersionUID = -3051163582728562957L; @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") protected String encodedKey; @Persistent @Extension(vendorName="datanucleus", key="gae.pk-name", value="true") private String id; @Persistent private long value; public String getEncodedKey() { return encodedKey; } public void setEncodedKey(String encodedKey) { this.encodedKey = encodedKey; } public String getId() { return id; } public void setId(String id) { this.id = id; } public long getValue() { return value; } public void setValue(long value) { this.value = value; } } ----------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~--- |
- [appengine-java] Replacing a child object in a parent objec... Patrizio Munzi
- [appengine-java] Re: Replacing a child object in a par... Patrizio Munzi