我擁有一個一對多的關係的兩個對象之間的負載對象組: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