Search code examples
javagoogle-app-enginegoogle-cloud-datastorereferenceproperty

How to model entity relationships in GAEJ?


I would like to know -an example is highly appreciated-

How to model relationships in Google App Engine for Java?

-One to Many
-Many to Many

I searched allover the web and I found nothing about Java all guides and tutorials are about Python.

I understood from this article that in Python the relationships are modeled using ReferenceProperty. However, I found nothing about this class in the Javadoc reference.

Furthermore, in this article they discussed the following:

there's currently a shortage of tools for Java users, largely due to the relative newness of the Java platform for App Engine.

However, that's was written in 2009.

At the end, I ended up modeling the relationships using the ancestor path of each entity. I discovered afterwords that this approach has problems and limit the scalability of the app.

Can you please guide me to the equivalent Java class to the Python's ReferenceProperty class? Or can you please give me an example of how to model the relationships in AppEngine using the java datastore low-level API.

Thanks in advance for your help.


Solution

  • Creating relationships between entities in GAE/J depends on db API that you are using:

    1. JDO: entity relationships.

    2. JPA: see docs.

    3. Objectify: single-value relationships.

    4. Low-level API: add a Key of one Entity as a property to another Entity: see property types.