3

I'm trying to use Spring Data Mongo's @DBRef(lazy = true) feature for lazy loading of an association but it doesn't seem to work. Even though it loads the Mainobject with an empty ReferencedObject, inside the reference object there is a CGLIB$CALLBACK_0 proxy object that has the association already loaded. Doesn't this beat the concept of lazy loading? Also, when I return the object to the client it returns the association twice:

mainObject: {
  field: value
  reference: { //same object
    refField: refValue
  },
  target: { //same object
    refField: refValue
  }
}

Isn't the goal for the lazy association to only fetch the object after some method call (like getRefObject() for example)? Also I'm failing to see how I can access the fetched object from its proxy once it is loaded since it is a private property and it doesn't have accessors...

PentaKon
  • 4,139
  • 5
  • 43
  • 80
  • please also add the according java sources and note that eg. using a lazy `DBRef` property as a constructor argument may force eager loading. – Christoph Strobl May 27 '16 at 11:42
  • As I'm having he same problem, was wondering if you had a workaround on it. All my Spring data documents are eagerly loaded even if they are marked lazy = true. The hole structure of parent-children objects is loaded out of my REST controller. – javadev Feb 09 '17 at 09:39
  • Nope we didn't solve it. I'm not sure if my debugger was causing the lazy loading when I was trying to access the object to watch its value but regardless, it seems that spring data always loaded that `CGLIB` object. – PentaKon Feb 09 '17 at 14:58

0 Answers0