首页 > Linux操作系统 > Linux操作系统 > Spring Data MongoDB cascade save on DBRef objects

Spring Data MongoDB cascade save on DBRef objects

原创 Linux操作系统 作者:jieforest 时间:2012-05-28 12:53:04 0 删除 编辑
[i=s] 本帖最后由 jieforest 于 2012-5-25 23:23 编辑

Spring Data MongoDB by default does not support cascade operations on referenced objects with @DBRef annotations as reference says:

The mapping framework does not handle cascading saves. If you change an Account object that is referenced by a Person object, you must savethe Account object separately. Calling save on the Person object will not automatically save the Account objects in the property accounts.

That’s quite problematic because in order to achieve saving child objects you need to override save method in repository in parent or create additional “service” methods like it is presented in here.

In this article I will show you how it can be achieved for all documents using generic implementation of AbstractMongoEventListener.

@CascadeSave annotation

Because we can’t change @DBRef annotation by adding cascade property lets create new annotation @CascadeSave that will be used to mark which fields should be saved when parent object is saved.


package pl.maciejwalkowiak.springdata.mongodb;

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录


  • 博文量
  • 访问量