Selecting Entity based on auto generated ID in google datastore

六眼飞鱼酱① 提交于 2019-12-11 18:14:12

问题


I have created an entity with few attributes but without specifying any key in which case an auto generated ID has been created in data-store.

     Entity en=new Entity("Job");

Now when I fetch such entities and try to store it in Java object, how can I get the auto generated ID (which I required to perform UPDATE operation later)? I have tried the below ways but it does not return Identifier value.

     en.getProperty("__key__");
     en.getProperty("ID/Name");
     en.getProperty("Key");

回答1:


You are probably looking for:

en.getProperty(Entity.KEY_RESERVED_PROPERTY)

mentioned in Key Filters (not an obvious place to find it).

Another approach would be to try:

en.getKey().getId()

mentioned in Entity JavaDoc and Key JavaDoc.



来源:https://stackoverflow.com/questions/22268257/selecting-entity-based-on-auto-generated-id-in-google-datastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!