views:

37

answers:

1

Hi I'm having the fallowing classes in Google app engine

import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

public class A {
    @PrimaryKey
    @Persistent
    String pk;

    @Persistent(dependent = "true")
    private B b;
    .
    .
    .
}

and

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;

public class B {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String name;
    .
    .
    .

}

I have a code that create the objects:

{
    PersistenceManager pm = PMF.get().getPersistenceManager();
    A a = new A("pk1");
    a.setB(new B(...));
    try {
    pm.makePersistent(a);
    } finally {
    pm.close();
    }
}

and later the same code update the objects, with the same String as the primary key for A.

{
        PersistenceManager pm = PMF.get().getPersistenceManager();
        A a = new A("pk1");
        a.setB(new B(...));
        try {
        pm.makePersistent(a);
        } finally {
        pm.close();
        }
}

Since I used the '@Persistent(dependent = "true")' I was expecting to ends up with one A object and one B object in the datastore, but I find one A object and B objects as the number of time that this code run.

Where am I wrong? Thanks, Eli

+1  A: 

You are wrong in expecting that GAE's datastore is a relational database. It's a key-value store and there is no concept of a cascading delete.

Let me suggest reading up on: http://en.wikipedia.org/wiki/Nosql

Swizec Teller
I understood differently from Google documentation: http://code.google.com/appengine/docs/java/datastore/relationships.html#Dependent_Children_and_Cascading_Deletes
Eli