2016-06-12 23 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的一個很好的概述。