How to model entity relationships in GAEJ?

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

How to model relationships in Google App Engine for Java?

-One to many
-Many for many

I searched everything on the Internet and I did not find anything about Java. All manuals and tutorials are dedicated to Python.

I realized from the article that in Python, relationships are modeled using ReferenceProperty . However, I did not find anything about this class in the Javadoc link.

In addition, in this article, they discussed the following:

There is currently a lack of tools for Java users, mainly due to the relative novelty of the Java platform for App Engine.

However, it was written in 2009.

In the end, I finished modeling the relationship using the path of the ancestor of each object. I found that this approach has problems and limits the scalability of the application.

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

Thanks in advance for your help.

+6
source share
2 answers

Creating relationships between objects in GAE / J depends on the db API you use:

+4
source

Just a hint. When you define a data model in terms of end-user requests and appropriately define your data model.

For example, let's take an example of a bookstore rental shop. In a traditional application, you will have three main objects:

-> Book

-> Client

-> Rent (for many-to-many solutions)

To display the report with which the client rents this book, you must send a request to the rental table, table of books and table of clients.

However, in GAE, this will not work because the join operation is not supported.

The solution I found (maybe a different solution) is to simulate the same three tables, but embed the book and customer definitions in the Rent table.

Thus, you will see a list of books rented by someone very fast and inexpensive. The only drawback is that if, for example, the name of the book changes, I have to go through all the embedded objects. However, how often does this happen compared to read-only queries.

As a resume, think about end-user requests

+1
source

Source: https://habr.com/ru/post/918640/


All Articles