0
votes

To make entity relationship we put a parent Key (parent relationship) or put a Key into a Entity property (child relationship).

Like this:

Key resultingKey = KeyFactory.createKey(parent, kind, key);
Entity userEntity = new Entity(resultingKey); // parent

Entity oldAddress = new Entity(KeyFactory.createKey(e.getKey, "Address", userEntity.getOldAddress.getId()));

userEntity.setProperty("oldAddress", oldAddress.getKey()); // child

However the question would be, for a parent Key, does the key should be a product of a Datastore put:

Key resultingKey = _ds.put(parentEntity);

Or creating a Key with KeyFactory is enough?

Furthermore, does this apply also for child Key?

1

1 Answers

0
votes

KeyFactory class enables direct creation of Key objects, both in the root entity group (no parent) and as the child of a given parent.

For More information : Documentation