Question

This is a best practice question regarding the Google Datastore. I'm trying to build object relationships and I'm seeing two options

  1. Directly embed a child class with @Persistent in the parent class
  2. Using the Google Key class and store my own foreign keys as strings in related classes

Third option is not available, JDO join

App Engine does not support join queries: you cannot query a parent entity using an attribute of a child entity. (You can query a property of an embedded class, because embedded classes store properties on the parent entity. See Defining Data Classes: Embedded Classes.)

My worry about using option 1 is that a simple search query I would return to much unneeded data.

Example being a Product Class and ProductDetail Class. When a customer searches my products they are just searching based on Category, Name and sorted by price. All of the simple info is in the Product class. In the ProductDetail class I hold large description strings, links to images, lists of key attributes. So in the Product Class I could embed the ProductDetail class or just create a foreign key property that holds the key value of the ProductDetail class.

So should I use option 2 then? I read somewhere don't treat the Google datastore like a relational DB. But in using option 2 that is just what I'm doing.

Was it helpful?

Solution

Agreed that option 1 is not scalable because the requester is often not interested in the embedded children. JDO and JPA are meant to perform lazy loading of data on demand but there is probably still overhead when no embedded data is needed.

Option 2 may look like strictly relational but it does not have to be. If your entities are not locked together into entity groups via ancestor keys, then the records are unrelated and free of constraints. You actually get to determine the tightness of consistency in your entity design and your application code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top