title: Updating child objects in Google App Engine using DataNucleus JDO
body: <p>I have spent several hours trying to work this one out and I just can't seem to get my child entities to update despite trying several suggestions.  I have looked at the GAE documents extensively and I have tried placing things in transactions, tried making them "owned" objects and making them part of the "default fetch group."  The objects are correctly persisted in the datastore after running the dummy "populateDatastore" method below and I can retrieve them from the datastore with no issue.  When I make changes, those changes are not persisted, although I am using the setter methods so JDO picks up the changes.  I am not a Java expert, so I may be doing something really obviously wrong and I don't see it. </p>
  
  <p><strong>Parent object</strong></p>
  
  <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
  public class Parent {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
  
    @Persistent
    private String invitationCode;
  
    @Persistent(defaultFetchGroup = "true")
    private Child child;
  
    // additional ivars and getters and setters
  }
  </code></pre>
  
  <p><strong>Child object</strong></p>
  
  <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
  public class Response {
  
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
  
    @Persistent(mappedBy = "child")
    private Parent parent;
  
    // additional ivars and getters and setters
  }
  </code></pre>
  
  <p><strong>I have several methods to retrieve and save objects.</strong>  </p>
  
  <pre><code>public void persistParent(Parent p, boolean closeSession){
    manager = PMF.get().getPersistenceManager();
    manager.makePersistent(p);
  
    if(closeSession) {
      manager.close();
    }
  }
  
  public Transaction beginTransaction() {
    int retries = 3;
    manager = PMF.get().getPersistenceManager();
    Transaction tx = manager.currentTransaction();
  
    try {
      tx.begin();
    }
    catch(com.google.apphosting.api.ApiProxy.CapabilityDisabledException e) {
      return null;
    }
    catch(Exception e) {
      return null;
    }
    return tx;
  }
  
  public boolean endTransaction(Transaction tx) throws Exception {
    int retries = 3;
    try {
      tx.commit();
    }
    catch(ConcurrentModificationException e) {
  if (retries == 0) {
        throw e;
      }
  --retries;
    }
    catch(com.google.apphosting.api.ApiProxy.CapabilityDisabledException e) {
      if (retries == 0) {
        throw e;
      }
  --retries;
    }
    catch(Exception e) {
      if (retries == 0) {
        throw e;
      }
      --retries;
    }
    finally {
      if(tx.isActive()) {
        tx.rollback();
      }
    }
  
    manager.close();
  
    return true;
  }
  
  public List&lt;Parent&gt; getParentWithID(String code, boolean closeSession) {
    Query q = PMF.get().getPersistenceManager().newQuery(Parent.class);
    q.setFilter("code == codeParam");
    q.declareParameters("String invitationCodeParam");
  
    List&lt;Invitation&gt; results = null;
    try {
      results = (List&lt;Parent&gt;) q.execute(code);
    } 
    finally {
      if(closeSession) {
        q.closeAll();
      }
    }
  
   return results;
   }
  </code></pre>
  
  <p><strong>Lastly, I have a dummy method to throw some data into the datastore for testing.  I add several children to the children list but for brevity's sake, I have cut out a lot of the redundant code.  I also persist several parent objects as well.</strong></p>
  
  <pre><code>Child c = new Child(arg1, arg2, arg3);
  c.setSomeIVarForChild(arg1);
  p = new Parent(arg1, arg2, arg3);
  p.getChildList().add(c);
  rsvpDao.persistParent(p, true);
  </code></pre>