orientechnologies / spring-data-orientdb

OrientDB implementation for SpringData

Home Page:http://forum.springsource.org/showthread.php?99627-OrientDB-support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lazy Loading

RAndrews137 opened this issue · comments

A behavior that we have noticed is that model objects do not have their member variables populated right away. If a getXYZ() call is made, then the object is fully populated. It seems that Orient Spring Data is lazy loading objects. That is normally a good thing, but it can cause issues when reflection is used by 3rd party libraries. Since reflection will access a member directly (not using get), the member variable may not be populated.

Do you have a way to turn off lazy loading and force the object to be fully populated after the query or save is invoked?

After more research, I found that the detachAll method from the OObjectDatabaseTx will populate the object. I went through the code and saw that the lazy loading is occurring during the OObjectDatabaseTx save() method. It is using the javaassist proxy wrapper. The detachAll is a temporary work around. It would be nice we we could somehow inform the db during the call not to use proxies

What do you prefer? an option that disable Lazy loading OR avoid completely it on spring data?

I think an option to disable would be best. It is possible to use the detachAll operation to fully populate objects, but that is needed per object each time. Perhaps an option can be set to decide if objects should be returned detached or not. Lazy loading should probably be the default. But, if someone has cases such as reflection, then they can set the option not to do lazy loading. The framework can then return objects that have already been detached. What do you think?

Disclaimer: I'm charge of this module since 2/3 weeks ago, I didn't wrote it, so I'm still learning.

I found that there is the Detach annotation, to be used at repository's method level:

    @Detach(DetachMode.ALL)
    List<Person> findByAddress_City(String city);

I'll start to enrich (almost write from ground up) the documentation.

If it solves your problem, please close the issue

Excellent. Let me try it out

Works great. THANKS :)