SpringSource/spring-data-mongodb — pull request #3 by maciejwalkowiak (2012-05-04 19:40:16+00:00)
Title: DATAMONGO-440 - implemented cascade operations on @DBRef fields 

Pull request contains implementation of cascading operations: save and delete on fields annotated with @DBRef. Implementation details:
- added new event: AfterDeleteEvent invoked in MongoTemplate after successful object removal
- added @DBRef#cascadeType property
- added CascadingMongoEventListener that intercepts objects before they are converted for save operation and before they are deleted for delete operation if appropriate @DBRef#cascadeType is set.
- in order to emit AfterDeleteEvent MongoOperations#remove methods had to be generified

This implementation is inspired by my research about cascading in Spring Data MongoDB described on blog: http://maciejwalkowiak.pl/blog/2012/04/30/spring-data-mongodb-cascade-save-on-dbref-objects/ where i found that it can be done now by implementing custom event listener but without internal framework changes its a little bit hacky (used reflection instead of Spring Data persistent-entity-like classes, additional annotation, impossible to implement cascading on delete).

If you like this idea and you have suggestions how this implementation can be improved i would be happy to make appropriate changes