unfortunately I still am having problem. if parent is already
persisted it does not work. I have a different post for that one.
http://groups.google.com/group/google-appengine-java/browse_thread/thread/a9955f8944a8c520

On Apr 19, 12:27 am, ylmz <[email protected]> wrote:
> Hi every body. I have a problem with my model and I cannot figure out
> what the problem is. So any help would be appreciated. to explain the
> problem I wrote some sample code:
> Here is my model:
>
> Class A hasonetomanyrelationship with B
> Class B hasonetomanyrelationship with C
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> class A {
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     public Key key;
>     @Persistent(mappedBy = "a")
>     @Element(dependent = "true")
>     public List<B> bList = new LinkedList<B>();
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> class B {
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     public Key key;
>     @Persistent(mappedBy = "b")
>     @Element(dependent = "true")
>     public List<C> cList = new LinkedList<C>();
>     @Persistent
>     public A a;
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> class C {
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     public Key key;
>     @Persistent
>     public B b;
>
> }
>
> in my code;
> 1) I created class A B and C
> 2) I persisted A
> 3) I retrieved A from DB and add B to its list.
> 4) I retrieved B from DB and add C to its list.
>
> but in step 4, I cannot retrieve B from DB, instead I get following
> exception
> javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of
> kind B with key B(4).
>
> Code :
>
> PersistenceManager pm = PMF.get().getPersistenceManager();
>
> //1)Create A,B,C
> A a = new A();
> B b = new B();
> C c = new C();
>
> //2)Persist A
> pm.currentTransaction().begin();
> try {
>    pm.makePersistent(a);
>    pm.currentTransaction().commit();} finally {
>
>    if(pm.currentTransaction().isActive())
>       pm.currentTransaction().rollback();
>
> }
>
> //3)get A from DB and add B to its list
> pm.currentTransaction().begin();
> try {
>   A newA = pm.getObjectById(A.class,a.key.getId());
>   newA.bList.add(b);
>   pm.currentTransaction().commit();} finally {
>
>    if(pm.currentTransaction().isActive())
>       pm.currentTransaction().rollback();
>
> }
>
> //4) get B from DB and add C to its list
> pm.currentTransaction().begin();
> try {
>    /********************Error*********************/
>    B newB = pm.getObjectById(B.class,b.key.getId());//we cannot
> retrieve this object. why?
>    newB.cList.add(c);
>    pm.currentTransaction().commit();} finally {
>
>    if(pm.currentTransaction().isActive())
>       pm.currentTransaction().rollback();
>
> }
>
> Please note that I am not sure that this is how I suppose to 
> implementownedonetomanyrelationship I got that implementation from
> following post
>
> http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to