In September 2009 I started to rebuild a site using a TomCat hosted web server I had developed that improved upon many good ideas found in Drupal.
In December 2009 I discovered Google's AppEngine, saw the potential, and decided to re-target my system to use this technology. I had designed the system to model objects using DB tables. In the AppEngine I have replaced them with JDO objects and built a system that generates both the JDO object and the smarts that add extra functionality to each field (such as validation and access rights). Objects are joined together using a Link Table technique described later in the document. This technique avoids all the entity boundary issues with Datastore as well as provides techniques for joining the different objects. It is really an implementation of what is described in http://code.google.com/appengine/docs/java/datastore/relationships.html#Unowned_Relationships . I have set up a site at http://www.rexcel.ca:8888/gems/bbb/load.home which both demonstrates and describes these techniques. In particular: link http://www.rexcel.ca:8888/gems/bbb/load.syswiki?ww=701000016#hdr-1-3 describes the joining technique. link http://www.rexcel.ca:8888/gems/bbb/load.syswiki?ww=701000013 describes the modeling technique. (By signing in as userid=visitor password=your_name the system will activate a read-only mode for many functions such as the permission system this technology extensively.) If there is enough interest I am prepared to make the code available. Steve Pritchard On Feb 8, 1:16 pm, Jake <[email protected]> wrote: > Hey, > > Relationships in GAE are a bit picky. It is my understanding that you > can only persist children by way of persisting their parents. So, in > your case, both Race and Runner are children of Result and you would > only persist the two result objects - the dependent children would be > persisted automatically. I'm willing to bet, though, that a single > race object cannot be the child of two different parent objects, > though I'm not certain. The details are all > here:http://code.google.com/appengine/docs/java/datastore/relationships.html > > For the most part, I've found that parent/child relationships are only > useful when the two are highly related - usually when I'm extending a > class to provide more data. (e.g. Race -> RaceDetails). > > The "easy" way to get around this is to store the objects in unowned > relationships, referencing other objects by IDs as described > inhttp://code.google.com/appengine/docs/java/datastore/relationships.ht.... > Then, with some fancy getters/setters that automatically query the > Datastore, you end up with the same result. See my example below. > > If anyone has any other advice, though, please contribute. I haven't > found a great way to handle this and I'm trying to avoid using GAE > specific libraries to help. > > Jake > > public class Race { > > private Key id; > ... > > } > > public class Result { > > private Key id; > private Key raceId; > > public Race getRace() { > //query datastore with getObjectById(Race.class, raceId); > } > > } > > On Feb 6, 7:15 pm, Rodolphe <[email protected]> wrote: > > > Hello, > > > I am very new to appengine, and I am trying a very basicmodelexemple: A > > Race class is linked to a Runner class through a Result class > > > When I am running the folloging code (the full code is attached): > > Race race = new Race("Paris", new Date(), 10); > > > Runner runner1 = new Runner("Smith"); > > Runner runner2 = new Runner("John"); > > > Result result1 = new Result(race, runner1, 1); > > Result result2 = new Result(race, runner2, 2); > > > PersistenceManager pm = PMF.get().getPersistenceManager(); > > try { > > race = pm.makePersistent(race); > > > runner1 = pm.makePersistent(runner1); > > runner2 = pm.makePersistent(runner2); > > > pm.makePersistent(result1); > > pm.makePersistent(result2); > > } finally { > > pm.close(); > > } > > > I get the following error: > > Detected attempt to establish Result(4) as the parent of Runner(2) but the > > entity identified by Runner(2) has already been persisted without a parent. > > A parent cannot be established or changed once an object has been persisted. > > org.datanucleus.store.appengine.FatalNucleusUserException: Detected attempt > > to establish Result(4) as the parent of Runner(2) but the entity identified > > by Runner(2) has already been persisted without a parent. A parent cannot > > be established or changed once an object has been persisted. > > at > > org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:204) > > at > > org.datanucleus.store.appengine.DatastoreRelationFieldManager$1.setObjectViaMapping(DatastoreRelationFieldManager.java:125) > > at > > org.datanucleus.store.appengine.DatastoreRelationFieldManager$1.apply(DatastoreRelationFieldManager.java:104) > > at > > org.datanucleus.store.appengine.DatastoreRelationFieldManager.storeRelations(DatastoreRelationFieldManager.java:78) > > at > > org.datanucleus.store.appengine.DatastoreFieldManager.storeRelations(DatastoreFieldManager.java:812) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPostProcess(DatastorePersistenceHandler.java:288) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(DatastorePersistenceHandler.java:241) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:225) > > at > > org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateManagerImpl.java:3185) > > at > > org.datanucleus.state.JDOStateManagerImpl.makePersistent(JDOStateManagerImpl.java:3161) > > at > > org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1298) > > at > > org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1175) > > at > > org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:669) > > at > > org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:694) > > at race.TestRace.test2(TestRace.java:58) > > > Any idea how I could solve this ? > > > Thank you in advance > > Rodolphe > > > TestRace.java > > 3KViewDownload > > > Race.java > > 1KViewDownload > > > Result.java > > 1KViewDownload > > > Runner.java > > 1KViewDownload -- 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.
