I have a class Page with a variable List<IMG> images.
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Page {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private final List<IMG> images;
...
}
My IMG class looks like this:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class IMG {
...
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private final int number;
...
}
I don't fully understand how the one to many key using
KeyFactory.Builder works. In order to make an instance of Page
persistent using the datastore, do I need to loop through every IMG
instance like this:
for(IMG image : images) {
KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), "page-id");
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
Key key = keyBuilder.getKey();
image.setKey(key);
pm.makePersistent(image);
}
or can I do this?
KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), "page-id");
for(IMG image : images) {
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
}
Key key = keyBuilder.getKey();
for(IMG image : images) {
image.setKey(key);
pm.makePersistent(image);
}
or can I just do this?
Page p;
...
Key key = KeyFactory.createKey(Page.class.getSimpleName(), page.getID
());
pm.makePersistent(page);
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.