Google says JDO doesn't do cascading deletes f

2019-07-23 06:05发布

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?

2条回答
贼婆χ
2楼-- · 2019-07-23 06:48

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());
查看更多
再贱就再见
3楼-- · 2019-07-23 07:01

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.

查看更多
登录 后发表回答