【问题标题】:Cascade delete in Google app engine datastoreGoogle 应用引擎数据存储中的级联删除
【发布时间】:2011-04-01 10:00:47
【问题描述】:

我正在 Google 应用引擎中上课

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 的主键。

{
        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 对象作为次数这段代码运行。

我哪里错了? 谢谢, 以利

【问题讨论】:

    标签: java google-app-engine google-cloud-datastore jdo


    【解决方案1】:

    您错误地认为 GAE 的数据存储是关系数据库。它是一个键值存储,没有级联删除的概念。

    让我建议继续阅读:http://en.wikipedia.org/wiki/Nosql

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    相关资源
    最近更新 更多