In this example, would Customer or AccountInfo properly be the entity group parent?
Posted
by Badhu Seral
on Stack Overflow
See other posts from Stack Overflow
or by Badhu Seral
Published on 2010-03-30T03:51:08Z
Indexed on
2010/03/30
3:53 UTC
Read the original article
Hit count: 284
In this example, the Google App Engine documentation makes the Customer
the entity group parent of the AccountInfo
entity. Wouldn't AccountInfo
encapsulate Customer
rather than the other way around? Normally I would think of an AccountInfo
class as including all of the information about the Customer
.
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);
© Stack Overflow or respective owner