I have a class Page with a variable List<IMG> images. <code> @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Page {
@PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private final List<IMG> images; ... } </code> My IMG class looks like this: <code> @PersistenceCapable(identityType = IdentityType.APPLICATION) public class IMG { ... @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; ... } </code> 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: <code> 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); } </code> or can I do this? <code> 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); } </code> or can I just do this? <code> Page page; ... Key key = KeyFactory.createKey(Page.class.getSimpleName(), page.getID ()); pm.makePersistent(page); </code> I never want to be able to access the IMG instances without the Page instance, do I even need to give the IMG instances keys at all? Thanks, Finbarr
-- 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.