2016-06-12 22 views
1

1.-创建对象的id无法创建在app-发动机的新对象:重复主键(ID:长型)

// Allocate a key for the conference -- let App Engine allocate the ID 
final Key<Conference> conferenceKey = factory().allocateId(profileKey, Conference.class); 
// Get the Conference Id from the Key 
final long conferenceId = conferenceKey.getId(); 

2.-创建objeto,添加ID

// Create Conference 
Conference conference = new Conference(conferenceId,userId,conferenceForm); 

3.-保存对象:

// Save Conference and Profile Entities 
ofy().save().entities(profile,conference).now(); 
ofy().save().entity(conference).now(); 

4.-错误,使用相同的id倍数倍(数据存储区谷歌)

datastore google platform

注:与同ANDROID_CLIENT_ID(释放模式)创建相同的对象

+2

你所看到的是正确的,因为ID = 1的两个实体具有不同的父项,所以它们具有不同的密钥。这是唯一完整的关键路径 - 名称/ ID仅在其父范围内唯一。 – tx802

+0

@ tx802 - 请发表评论作为回答。这是正确的。 –

回答

3

你们看到的是正确的。您的屏幕截图显示ID = 1的2个实体,但具有不同的父项(祖先路径)。

数据存储区密钥由其完整的祖先路径形成,它是唯一的密钥 - 不是ID /名称。该ID /名称在它的父级范围内是唯一的。如果一个实体没有祖先,那么你会希望这个ID是唯一的。

This page给出了Keys的一个很好的概述。