使用 objectify,我使用 App Engine 自动生成的 ID 为我的实体创建 ID,如下所示:
@id
Long ID;
我将 null 放入变量 ID,因此 App Engine 会自动为我的实体生成 ID。
通过对象化函数创建 key :
Key.create(java.lang.Class<? extends T> kindClass, long id)
我可以得出这样的结论:为没有任何父关系的实体自动生成的 ID 是唯一的吗?
最佳答案
Each entity in Datastore has a key that uniquely identifies it. The key consists of the following components:
- The namespace of the entity, which allows for multitenancy
- The kind of the entity, which categorizes it for the purpose of Datastore queries
- An identifier for the individual entity, which can be either a key name string an integer numeric ID
- An optional ancestor path locating the entity within Datastore hierarchy
这些组件的联合使 key 唯一。 因此,自动生成策略保证 ID 在相同的 namespace|parent|kind|id 或仅 kind|id 中是唯一的如果没有 parent
来源:https://cloud.google.com/appengine/docs/java/datastore/entities
关于java - App Engine 是否自动生成 Long @id 在实体范围内是唯一的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29483724/