我拥有一个一对多的关系的两个对象之间的负载对象组:JDO,GAE:通过孩子的关键
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class AccessInfo {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private com.google.appengine.api.datastore.Key keyInternal;
...
@Persistent
private PollInfo currentState;
public AccessInfo(){}
public AccessInfo(String key, String voter, PollInfo currentState) {
this.voter = voter;
this.currentState = currentState;
setKey(key); // this key is unique in whole systme
}
public void setKey(String key) {
this.keyInternal = KeyFactory.createKey(
AccessInfo.class.getSimpleName(),
key);
}
public String getKey() {
return this.keyInternal.getName();
}
和
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PollInfo
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(mappedBy = "currentState")
private List<AccessInfo> accesses;
...
我创建的类PollInfo做出的一个实例它坚持不懈。没关系。 但是然后我想通过AccessInfo键加载这个组,并且我收到异常NucleusObjectNotFoundException。 是否可以按小孩的密钥加载小组?
“密钥”(对于AccessInfo)是一个包含12个字符的随机字母数字字符串。 PersistenceManager pm = PMF.get()。getPersistenceManager(); \t \t Transaction tx = pm.currentTransaction(); \t \t尝试{ \t \t \t tx.begin(); \t \t \t AccessInfo ai; \t \t \t尝试{ \t \t \t \t AI = pm.getObjectById(AccessInfo.class,KeyFactory.createKey( AccessInfo.class.getSimpleName(), 键)); – Solvek