Hi, everybody.

I'm new to GAE and I've been reading a few books/tutorial about it.
However, something is still not clear to me. It always describes that
a key would have a reference to the entity parent. So, if I have the
following entity User, when it is persisted the Image will have a key
saying the User is its parent, right?

public class User {
    private Key key;
    private List<Image> images;
}

public class Image {
    private Key key;
}

Let's say we have users:
User/1
User/2

So we will have images like:
User/1/Image/1
User/1/Image/2
User/2/Image/5
User/2/Image/6

Can we have by any chance images like Image/1 or Image/100? If so,
what happens if we assign it to a user and persist a user? Will
another image be created as a copy of the previous image but with a
new key (once keys can't change)?

What I am saying is something like:

Image image = new Image();
pm.makePersistent(image);

User user = new User(); // or retrieve it
user.getImages().addImage(image);
pm.makePersistent(user);


I am a bit worried because some of the “child” entities can be linked
to it's parent, but I don't want it to be part of the key. For
example, User sends Message. I will have a field in Message called
author. I'm afraid if I have user.messages() with a no persisted
Message, it's key will be something like User/1/Message/100 instead of
only Message/100. Or, as Message has an author, it could persist a new
User… I guess this won't happen though, even if the first User is not
persisted yet. In other words:

public class User {
    private Key key; // When is it recommended to use Key and when is
it better to use Long
    private List<Message> sentMessages;
    private List<Message> receivedMessages;
}

public class Message {
    private Key key; // What if both User and Message would use id?
    private User from:
    private User  to;
}


And, I don't know exactly what identityType=IdentityType.APPLICATION
would change. It says if I don't use it, the datastore will take care
of it, but I don't need to have a reference to the key in my class?
And I think by using any method I could “setId(a number)" before I
persist it and if it doesn't exist, it will be created? If I don't set
it, it would be set automatically…

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to