简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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