5

I'm using JDO with Google App Engine for storage and I'm wondering what is the difference between the Key object and Long for id?

I find the long ID more practical, am I missing anything?

Thanks.

Elie
  • 6,915
  • 7
  • 31
  • 35

1 Answers1

6

A Key is globally uniquely identifier which uniques identifies an entity across all of app engine. It consists of two pieces:

  1. A path describing what app the entity belongs to, any ancestor keys, and the entity's kind.
  2. An ID (a long) or a key name (a string).

Regardless of whether you choose to use a long or a string as the second piece, there is a Key object is associated with every entity stored in the datastore.

David Underhill
  • 15,896
  • 7
  • 53
  • 61
  • 4
    Good description, however also important to mention that if you use Key then you tie your code to Google (or at least presence of their Key class), whereas if you use long/String etc then you have portability (of identity) in your code – DataNucleus Mar 15 '11 at 20:12
  • Great explanation and Good point DataNucleus. I'll stick with the Long primary key for better portability in the future. Thanks! – Elie Mar 17 '11 at 08:36
  • As of 2014, Keys also embed an optional Namespace field. – Deleplace Jul 26 '14 at 10:19