Search code examples
mysqlgoogle-app-enginejdogoogle-cloud-datastore

Do I need to be utilizing the parent-child relationships of JDO in Google App Engine?


I want my application to be as portable as possible so that if the Google Cloud Datastore turns out not to be the best solution then I can quickly and easily switch to MySQL, but there are some inherent differences in the way the internet wants me to define my models for these two paradigms.

For MySQL, my models would simply have a field for referencing the ID of related models. However, JDO gives me the ability to easily reference the actual models themselves.

I.E.: My MySql model would, I think, look something like this:

class Parent{
    private String key;
    private String childId;
}

But JDO would be:

class Parent{
    private String key;
    private Child child;
}

This difference has caused me to decide to utilize the first method and worry about querying for the actual Child object on my own, but I am wondering if I am just making things hard on myself for something that may or may not be important. Are there specific reasons that what I am planning to do is wrong?


Solution

  • I believe the terminology in the App Engine JDO docs for these cases is that storing the key on a property forms an "unowned" relationship, and doing the other thing is an "owned" relationship. With Datastore, an owned relationship forms a datastore entity group, which is like storing all of the entities in the group as one record.

    I don't like forming entity groups without explicitly wanting to be able to act on all members of a group transactionally, since grouping impacts concurrent updates. If I'm merely relating two data objects so I can follow a reference from one to the other, and I don't need transactionality, I'd rather take the time to follow the reference to the second entity than make an unnecessary entity group and hope it all works out. In other words, I'd prefer unowned relationships (storing keys) to owned relationships unless I know that I need transactionality.

    This concept has no equivalent in relational databases. [Thanks to Billy Frost for the correction.] So you can do either and retain portability.

    https://developers.google.com/appengine/docs/java/datastore/jdo/relationships