在此示例中,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