One case is when you need to save several different entities that all reference each other. Let's say A has a reference to B, and B has a reference to A. If you relied on key autogeneration you would need 3 puts:
* Put A (which initializes the id) * Set B.a to the id of A, put B * Set A.b to the id of B, put A again Instead you can just allocate two ids up front and put both entities together (in a batch if you'd like). Jeff On Wed, Jun 15, 2011 at 3:26 AM, Drew Spencer <[email protected]> wrote: > Thanks Jeff, I think I will use Longs as you suggest. I was > originally thinking "why add an extra piece of data when there's a unique > value there?" Well, now I know why! > > Just one question - the DatastoreService.allocateIdRange() - when would > this be used? I have read the javadoc and understand that it reserves the > IDs for bulk loading etc, but can you give an example of when it might be > used. At the moment I have some code that creates 5 lists of my 5 entities > (dummy data), puts all 5 lists to the datastore, links them up using keys, > and then puts them all again. Is there a better way to do this? > > Thanks again for being so helpful. > > Drew > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-appengine-java/-/ErZFcwnAoRUJ. > > 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. > -- 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.
