我有兩個對象一個用戶和一個角色,我使用JDO和Google應用程序引擎進行持久化。這兩種數據類型彼此相關,因爲它們之間沒有多少關係。我試圖模仿那些在gae-tutorial中被描述爲持有相應對象的關鍵字的集合。當我創建我的對象時,這些鍵是空的。所以爲了獲得一些生成的密鑰,我使這些對象持久。之後,我將這些引用鍵添加到這些對象。但是這些密鑰最終沒有得到存儲。Google App Engine:存儲無主對多關係
除了設置鍵之外,我還操縱一些其他屬性(在makePersistent之後)。這些更改稍後會反映在數據存儲中。但是,在makePersistent之後所做的所有關鍵更改都不要交給數據存儲。如果我在makePersistent之前設置這些密鑰,它們就會按照它們的方式進行存儲。但是,這並不是解決方案,因爲至少有一個對象必須在持久化後才能在邏輯上接收密鑰引用。
下面是一些示例代碼,說明問題。
存儲這些密鑰的最佳做法是什麼?
持久化的作用類
public class Role {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key Role_id;
@Persistent
private Set<Key> Users = new HashSet<Key>();
...
}
持久化的用戶類其產生1個角色和1個用戶和試圖設置在兩側上的關鍵引用
public class User {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key User_id;
@Persistent
private String EMail = null;
@Persistent
private Set<Key> Roles = new HashSet<Key>();
...
}
代碼提取物。他們的關鍵變化不會在數據存儲中結束。但是,電子郵件地址的更改會寫入數據存儲區。 ...
PersistenceManager pm = PMF.get().getPersistenceManager();
Role GlobalAdmin = new Role();
User Daniel = new User();
try {
pm.makePersistent(GlobalAdmin);
pm.makePersistent(Daniel);
} catch (Exception e){
System.out.println("Storing failed: " + e.getMessage());
}
GlobalAdmin.addUser(Daniel.getUser_id());
Daniel.addRole(GlobalAdmin.getRole_id());
Daniel.setEMail("[email protected]");
pm.close();
...
沒有人知道如何回答這個簡單的問題嗎?看起來GAE並不像谷歌那樣受歡迎,而且VMWare會喜歡它...... – 2010-12-13 00:44:52