繁体   English   中英

在Google App Engine数据存储中进行级联删除

[英]Cascade delete in Google app engine datastore

我在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;
    .
    .
    .
}

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;
    .
    .
    .

}

我有一个创建对象的代码:

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

之后,相同的代码更新对象,并使用与A的主键相同的String。

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

由于我使用了'@Persistent(dependent =“ true”)',因此我期望在数据存储区中最终得到一个A对象和一个B对象,但是我发现一个A对象和B对象作为这段代码的时间跑。

我哪里错了? 谢谢,以利

您期望GAE的数据存储区是一个关系数据库是错误的。 这是一个键值存储,没有级联删除的概念。

让我建议您阅读以下内容: http : //en.wikipedia.org/wiki/Nosql

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM