Hi Jeff, I'm the author of that comment.  The practice is discouraged
because of the first reason you give - we're worried that users will do some
writes where they provide the Long primary key and some writes where they
let the datastore assign it and then end up silently overwriting data.
 There is no performance problem associated with setting a Long primary key,
so if you have a natural key provided by some other system that is
guaranteed to be unique it should work (and perform) just fine.

Max

On Thu, Nov 26, 2009 at 3:10 AM, Jeff Schnitzer <j...@infohazard.org> wrote:

> I store a record that has a natural Long primary key (a facebook user
> id).  I currently create a Key with that id and insert this record.
>
> I just noticed this comment on the Entity(Key) constructor:  "Creating
> an entity for the purpose of insertion (as opposed to update) with a
> key that has its id field set is strongly discouraged unless the key
> was returned by a KeyRange."
>
> Is this "strongly discouraged" because the author of that comment is
> afraid I will accidentally insert an entity with a null key and the
> resulting generated key might conflict with existing data?  Or is this
> strongly discouraged because there is an actual performance problem
> doing this on the server?
>
> I expect a staggering large write volume, all of which will overwrite
> the old records without any need to load them first.  I need to do
> this the most efficient way possible.  Is my current solution the best
> performing, or is it better to stringify the user id and use that as a
> keyname?
>
> Thanks in advance,
> Jeff
>
> --
>
> 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<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> 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 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