views:

358

answers:

1

I persist in storage an object with a child inside it. There is an "Owned One-to-One Relationships" (http://code.google.com/appengine/docs/java/datastore/relationships.html#Owned%5FOne%5Fto%5FOne%5FRelationships). Now I want to load objects but I have ONLY id of child's object. Is it possible?

     Child c = new Child("chld23", "I'm a child");
     Parent p = new Parent("I'm a parent", c);

        PersistenceManager pm = PMF.get().getPersistenceManager();
        // Creating
        try {
            pm.makePersistent(p);
        } finally {
           pm.close();
        }

        // Retrieving
        pm = PMF.get().getPersistenceManager();
        Child ch2 = null;
        try{
            ch2 = pm.getObjectById(Child.class, "chld23"); // Exception occurs: org.datanucleus.exceptions.NucleusObjectNotFoundException: Could not retrieve entity of kind Child with key Child("chld23")
        } finally {
           pm.close();
         }
    }
}

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Parent {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent private String name;
    @Persistent
    private Child child;
    public Parent(){
    }
    public Parent(String name, Child child) {
     super();
     this.name = name;
     this.child = child;
     child.setParent(this);
    }
    ...
}

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Child {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    private String key;
    @Persistent private String name;
    @Persistent(mappedBy = "child")
    private Parent parent;
    public Child() {
    }
    public Child(String id, String name) {
     super();
     this.key = id;
     this.name = name;
    }
    ...
}
A: 

have you found the answer? I have the same problem

ZeoS
Here is the answer http://stackoverflow.com/questions/1657007/jdo-gae-load-object-group-by-childs-key
Solvek