spring-projects/spring-data-mongodb — pull request #151 by thomasdarimont (2014-03-18 21:17:55+00:00)
Title: DATAMONGO-880 - Improved handling of persistence of lazy-loaded DBRefs.

DATAMONGO-880 - Improved handling of persistence of lazy-loaded DBRefs.

Added LazyLoadingProxy interface that will be implemented by every LazyLoading-proxy that is created by the DefaultDbRefResolver. Clients can now cast those proxies to this interface and call it's methods initialise a proxy explicitly or to get the referenced DBRef if possible.
We now store the DBRef that lead to the creation of a LazyLoadingProxy in order to be able to reuse it in case one assigns the proxy to a field that should be a DBRef. This avoids unnecessary forth-and-back conversion.
Previously saving of proxies wasn't possible since the mapping infrastructure did not know how to extract the entity information from the proxy. We now either store the DBRef backed by the proxy directly or we initialise the proxy first and use the result of LazyLoadingProxy#initialize().