Hi,

I'm not understanding how to implement a simple unowned relationship.
I have two classes like:

  class Farm {
    List<Key> mHorses;
  }

  class Horse {
    @PrimaryKey
    Key mKey;
  }

so a Farm can have some horses. I'd like to create a new horse, then
put it on a farm, in one transaction. But how do I know the key of the
horse during the transaction?:

  Farm farm = loadFarm(...);
  Horse horse = new Horse();
  horse.setName("Roger");
  try {
    tx = pm.currentTransaction();
    tx.begin();
    pm.makePersistent(horse); // is the key available now?
    farm.mHorses.add(horse.mKey);
    pm.makePersistent(farm);
    tx.commit();
  }

when is the Horse.mKey value actually set and ready for use? Or do I
have to do this as two separate atomic operations:

  1) Save the horse which generates its mKey value.
  2) If that worked, add it to the farm, persist the farm again.
  3) If that worked, all good, if not, have to delete the horse cause
now it's in limbo?

Thanks

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

Reply via email to