开发者

Google says JDO doesn't do cascading deletes from Datastore. So how do you do it?

Google says:

Note: The JDO implementation does the work to delete dependent child objects, not the datastore. If you delete a parent entity using the low-level API开发者_JAVA百科 or the Admin Console, the related child objects will not be deleted.

So how DO I delete an Entity which has child entities that are ArrayList ???

Shouldn't this be a basic feature - to delete the dependent child entities from a parent Entity?


Its not saying that JDO doesn't do cascading dependent children. In fact, it's saying that it does indeed do them, but it's the code in the JDO that does such. As such, if you touch the database directly (SQL or admin tool), the dependant children won't be deleted.


I actually solved this by getting all the dependent children in separate queries and deleting them. Just deleting the parent didn't delete the dependent children from the datastore.

This was accomplished using the setAncestor() function

    // delete all children phrases

    Query phrase = new Query("Phrase");
    phrase.setAncestor(parentKey);
    results = datastore.prepare(phrase).asList(FetchOptions.Builder.withDefaults());
    for (Entity result : results)
        datastore.delete(result.getKey());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜