Just use the allocator to generate an id. Look at the javadocs for DatastoreService.allocateIds(). It's the same mechanism that GAE uses to autogenerate numeric ids when saving entities. It scales.
Make up some kind of fake Kind - or even use the URLInfo kind. Allocate an id every time you construct a new URLInfo. They will not be exactly monotonically increasing but they will be guaranteed unique. Strategies based on hashes are probably a bad idea. I'm guessing you want the shortest value possible, but shorter hashes will be more likely to produce collisions. Jeff On Tue, Jul 31, 2012 at 11:32 PM, Neo <[email protected]> wrote: > I have an Entity type say URLInfo which keeps info about URLs. The primary > key of this entity is URL itself ( that makes sure that I always have unique > URLs in the datastore). I also want unique integer id for each url so that > sharing the id becomes easier. Though, I can use GUIDs, but that is not a > preferred thing for me. How can I achieve this requirement? Integer Ids need > not be sequential ( preferred, if they are). Entities can be generated at a > faster rate (that means I can't keep a common counter to update each time I > generate a new URL record). This is what I have tried so far - In the > URLInfo class, I defined a field - Long Id and annotate it with > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) in the hope that > it will get automatically generated with the unique value. But when I save > the new entity (with id set as null), it saves the entity in the datastore > but doesn't assign any value to this field. > > I am trying all this on a local machine. I am using Java/JDO. > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-appengine/-/DQYcuXI9AJYJ. > 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?hl=en. -- You received this message because you are subscribed to the Google Groups "Google App Engine" 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?hl=en.
