I am trying to persist Java objects to the GAE datastore.
I am not sure as to how to persist object having ("non-trivial") referenced object.
That is, assume I have the following.
public class Father {
String name;
int age;
Vector<Child> offsprings; //this is what I call "non-trivial" reference
//ctor, getters, setters...
}
public class Child {
String name;
int age;
Father father; //this is what I call "non-trivial" reference
//ctor, getters, setters...
}
The name field is unique in each type domain, and is considered a Primary-Key.
In order to persist the "trivial" (String, int) fields, all I need is to add the correct annotation. So far so good. However, I don't understand how should I persist the home-brewed (Child, Father) types referenced. Should I:
- Convert each such reference to hold the Primary-Key (a name String, in this example) instead of the "actual" object, so
Vector<Child> offsprings;becomesVector<String> offspringsNames;?If that is the case, how do I handle the object at run-time? Do I just query for the Primary-Key from
Class.getName, to retrieve the refrenced objects? - Convert each such reference to hold the actual Key provided to me by the Datastore upon the proper
put()operation? That is,Vector<Child> offsprings;becomesVector<Key> offspringsHashKeys;?
I have read all the offical relevant GAE docs/example. Throughout, they always persist "trivial" references, natively supported by the Datastore (e.g. in the Guestbook example, only Strings, and Longs).