java - Getting GAE Entity by Key -
i've been trying entity gae datastore key, of type key. here's code i'm using retrieve key:
strid = myvideo.getkey().tostring(); the type of myvideo entity. value myvideo.getkey().tostring() method returns "video(121)". here's code tries retrieve entity via entity's key:
entity video = ds.get(key); the following exception gets thrown when trying retrieve entity datastore:
no entity found matching key: video("video(121)")
is there way encoded key object of type entity?
the various ways convert between keys , strings documented in app engine docs here. in short, string version of key, want this:
string employeekeystr = keyfactory.keytostring(employeekey); to convert key can fetch ds.get(), should this:
key employeekey = keyfactory.stringtokey(employeekeystr); the string version you're fetching .tostring() human readable version of key, not intended passed around machine-readable identifier.
of course, if intending pass keys around code, there's no need convert them strings @ all. conversely, if want use them external identifiers, want read rest of linked section, discusses ancestors, ids , names; of time when want pass identifiers around, name or id alone suffice, , shorter , more readable full key.
Comments
Post a Comment