密钥与ID/名称? [英] Key vs ID/Name?

查看:66
本文介绍了密钥与ID/名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想为我的实体创建自动生成的密钥,所以我指定自己的密钥:

I do not want to create an autogenerated key for my entities so I specify my own:

Entity employee = Entity.newBuilder().setKey(makeKey("Employee", "bobby"))
        .addProperty(makeProperty("fname", makeValue("fname").setIndexed(false)))
        .addProperty(makeProperty("lname", makeValue("lname").setIndexed(false)))    
        .build();

CommitRequest request = CommitRequest.newBuilder()
    .setMode(CommitRequest.Mode.NON_TRANSACTIONAL)
    .setMutation(Mutation.newBuilder().addInsert(employee))
    .build();
datastore.commit(request);

当我查看该实体的外观时,它看起来像这样:

When I check to see what the entity looks like it looks like this:

如果我指定了自己的密钥(鲍比),为什么会生成此自动生成的密钥?似乎还创建了bobby,但是现在我有了bobby和此自动生成的密钥.密钥和ID/名称有什么区别?

Why is this auto-generated key generated if I specified my own key (bobby)? It seems bobby was also created, but now I have bobby and this autogenerated key. What is the difference between the key and id/name?

推荐答案

这是密钥的url安全版本,适用于链接.使用 KeyFactory.stringToKey 转换为实际的密钥,您会看到它包含您的字符串名称.

This is the url-safe version of your key, suitable for use in links. Use KeyFactory.stringToKey to convert it to an actual key, and you'll see that it contains your string name.

这篇关于密钥与ID/名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆