开发者

JDO, GAE: Load object group by child's key

开发者 https://www.devze.com 2022-12-10 19:06 出处:网络
I have owned one-to-many relationship between two objects: @PersistenceCapable(identityType = IdentityType.APPLICATION)

I have owned one-to-many relationship between two objects:

@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.开发者_C百科class.getSimpleName(),
                key);
    }

    public String getKey() {
        return this.keyInternal.getName();
    }

and

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PollInfo
{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent(mappedBy = "currentState")
    private List<AccessInfo> accesses;
    ...

I created an instance of class PollInfo and make it persistence. It is ok. But then I want to load this group by AccessInfo key, and I am getting exception NucleusObjectNotFoundException. Is it possible to load a group by child's key?


Perhaps if you quote your code for retrieving the AccessInfo object and how you got the "key" that you used ?

0

精彩评论

暂无评论...
验证码 换一张
取 消