How exactly does spring-data-mongodb handle constructors when rehydrating objects?

纵然是瞬间 提交于 2019-12-05 06:36:49

The population process is two fold and orthogonal to some degree. Mostly, you've already stated the correct behavior. The constructor is invoked to create an object instance. The parameter values are retrieved from the DBObject read and might cause a recursive creation of objects in case you hand complex objects into the constructor that need to be unmarshalled from a nested DBObject.

The next step is that your persistent fields get populated. The only difference in your case to the case with a default constructor is that we remember the field values you handed into the constructor and do not re-populate those.

The dateproperty in your example would still get set after the initialization in the constructor if the source document the object is materialized from contains a value for date.

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