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

两盒软妹~` 提交于 2019-12-11 06:08:53

问题


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 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?


回答1:


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.




回答2:


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());


来源:https://stackoverflow.com/questions/6543664/google-says-jdo-doesnt-do-cascading-deletes-from-datastore-so-how-do-you-do-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!