You can follow something like that

class Parent {
  ....
  @Persistent
  private List<Long/Key> childList;

  // non Persistent
  private List<Child> list;
  ...
}

class Child {

   @PrimaryKey
   private Long/Key key;
   ...
}

// before save Parent
  private void beforeSave(EntityManager em,Parent pa) {
     if (pa.getList() != null) {
       List<Long> chList = new ArrayList<Long>();
       for (Child ch : pa.getList) {
         pm.makePersistent(ch);
         pm.flush();
         chList.add(ch.getKey());
       }
       pa.setChildList(chList);
    }
  }

  private void afterLoad(EntityManager em,Parent pa)  {
    List<Child> chList = new ArrayList<Child>();
    for (Long key : pa.getChildList()) {
       Child ch = pm.getObjectById(Child.class,key);
       chList.add(ch);
    }
    pa.setList(chList);
  }


  PersistenManager pm;
  ....

  // main service
  Parent pa = pm..getObjectById(...)
  afterLoad(pm,pa);
  ...
  ...
  beforeSave(pm,pa);
  pm.makePersistent(pa);

  List<Parent> pList = pm.queryExecute();
  for (Parent pa : pList) {
    afterLoad(pm,pa);
  }
  ...
  // etc

In order to avoid repeating the same beforeSave and afterLoad for all
Entity classes having "onowned" relationship you can apply Annotation
and, by  the use of reflection, develop generic approach for all
classes having this feature.




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to