为什么 Google datastore 允许重复 ID/Name?管理这个的最佳实践是什么?

Why Google does datastore allow duplicated ID/Name? And what is the best practice for managing this?

好的,现在看这段代码

public void insertUser1(){
   public static Key personKey=KeyFactory.createKey("Person", "PersonName");
   Entity userEntity=new Entity("User", "User1", personKey);
   userEntity.setProperty("FirstName","Tom");
   datastore.put(userEntity);
}

运行insertUser1();后,可以在datastore中看到

ID/Name - FirstName
User1     - Tom

现在,我想修改 user1 的名字,但这次我使用此代码

public void modifyUser1(){
   Entity userEntity=new Entity("User", "User1");
   userEntity.setProperty("FirstName","Mary");
   datastore.put(userEntity);
}

现在,再次检查数据存储,我可以看到 2 个条目:

ID/Name - FirstName
User1     - Tom
User1     - Mary

为什么 Google datastore 允许重复 ID/Name?管理此问题的最佳做法是什么?

第一个有 parent,第二个没有。

public static Key personKey=KeyFactory.createKey("Person", "PersonName");
Entity userEntity=new Entity("User", "User1", personKey);

有 id Key(Key(Person,PersonName), User, User1)

但是这个:

new Entity("User", "User1");

只是 Key(User, User1)。所以这是不同的ID。

基本上它是每个数据库唯一的实体 Key,它由 Parent Id(或空)和 实体 ID.

阅读有关实体 parent 的更多信息:https://cloud.google.com/appengine/docs/java/datastore/#Java_Ancestor_paths