问题
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