gpt4 book ai didi

google-app-engine - 自动 ID 分配器会返回我在其他实体上任意设置的 ID 吗?

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:39 25 4
gpt4 key购买 nike

如果我任意将新实体的 ID 设置为 1000,而不先使用 allocateIds,是否可以自动为后来的实体赋予 ID 1000 并覆盖我的原始实体?

在伪代码中,如果我有:

Entity e1;
e1.setId(1000);
datastore.put(e1);

...稍后...

Entity e2;
datastore.put(e2);

e2 是否有机会自动获得 ID 1000 并覆盖 e1?

最佳答案

Java API documentation 中所述

Creating an entity for the purpose of insertion (as opposed to update) with this constructor is discouraged unless the id was obtained from a key returned by a KeyRange obtained from AsyncDatastoreService.allocateIds(String, long) or DatastoreService.allocateIds(String, long) for the same kind.

另见 Python documentation :

Be aware, however, that the datastore is not guaranteed to avoid app-assigned IDs. It is possible, though unlikely, that the datastore will assign a numeric ID that will cause a conflict with an entity with an app-assigned ID. The only way to avoid this problem is to have your app use allocate_ids() to obtain a batch of IDs. The datastore's automatic ID generator will not use IDs that have been obtained using allocate_ids(), so your app can use these IDs without conflict.

您不应该使用数据存储尚未分配的 ID 创建实体,如果您想提供用户定义的标识符作为实体键的一部分,请改用 key_name

关于google-app-engine - 自动 ID 分配器会返回我在其他实体上任意设置的 ID 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8948486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com