DBRefs (Mongo Document references) not fetched eagerly

前提是你 提交于 2019-11-30 22:21:55

You are correct, any DBRefs are eagerly fetched, but they are not eagerly saved (AFAIK). If A has a reference to B, when you save A, Spring Data/MongoDB doesn't automatically save B, you have to.

// Incorrect, upon retrieval a.getB() == null
A a = new A();
a.setB(new B());
repositoryA.save(a);

// Correct (to the best of my knowledge)
B b = repositoryB.save(new B());
A a = new A();
a.setB(b);
repositoryA.save(a);

Moving over to the Spring Data Mongo M5 build resolved this. So, must be a bug until then.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!