Reputation: 35276
What is the clear difference of a Ancestor Key and a Parent Key?
Is it basically the same? How does it differently affect a get() method and a Query
method?
From the GAE KeyFactory
class, we can only see the Key
parent and no such ancestor Key
.
public static Key createKey(Key parent, String kind, String name) {
return createKey(parent, kind, name, (AppIdNamespace)null);
}
Then use the key like this:
Entity e = new Entity(key); // key may include a parent Key
In a typical query, like in a guestbook app. We can make a Key as an ancestor, so we can have different guestbooks to which Entities could be saved like:
Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
Query q = new Query(kind, guestbookKey); // guestbookKey = ancestor
So what is the difference of a Parent and Ancestor, are they basically the same thing without any difference, the same thing with just different notation?
Upvotes: 1
Views: 271
Reputation: 881675
A Parent
means an immediate parent. An Ancestor
is a more general term, encompassing immediate parents, parents of parents, parents of parents of parents, and so forth -- exactly the same use as in English.
An "entity group", the kind on which you can ask for an atomic transaction, need to be made up of entities with a common ancestor -- they don't need to all have the same (immediate) parent, but their lines of descent do need to meet at one common ancestor some way "up the line" (not necessarily the same number of steps for all entities involved).
When you createKey
based on a parent
key, that parent key may in turn have been made with its own parent -- and if that is so, then the parent's parent is not itself the parent of what you're creating now, but, it is an ancestor thereof.
Upvotes: 5