在此示例中,Google App Engine documentation使AccountInfo
實體的實體組父項成爲Customer
實體。 AccountInfo
封裝Customer
而不是其他方式?通常我會想到AccountInfo
課程包括關於Customer
的所有信息。在此示例中,Customer或AccountInfo是否應該是實體組的父級?
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
@PersistenceCapable
public class AccountInfo {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
public void setKey(Key key) {
this.key = key;
}
}
// ...
KeyFactory.Builder keyBuilder = new KeyFactory
.Builder(Customer.class.getSimpleName(), "custid985135");
keyBuilder.addChild(AccountInfo.class.getSimpleName(), "acctidX142516");
Key key = keyBuilder.getKey();
AccountInfo acct = new AccountInfo();
acct.setKey(key);
pm.makePersistent(acct);
正是。客戶可以擁有人員賬戶(顯然「客戶」實際上應該是「實體」 - 就像在商業,法律或個人實體中一樣),並附有客戶/供應商/員工角色,因爲您的客戶可能同時也是您的供應商。 ',除非您在accountinfo中編碼角色 - 但是「實體」也需要擁有多個帳戶。 – TomTom 2010-03-30 04:38:32