Lazy Init / Eager / Join Fetch collection strategy ? What to choose ?

#1

Hello,

I'm doing some tests to choose the best collection fetch strategy.

I have entities with many lazy collections and i don't want to load them all. (depends on context)

In JPA / Hibernate world it exists some tests demonstrating how to choose the best strategy.

For example :

http://zeroturnaround.com/rebellabs/how-to-use-jpa-correctly-to-avoid-complaints-of-a-slow-application/

In this article,join fetch seems to be the right choice.

What about ObjectDb ? The implementation is totally different.

Is an "All eager strategy" more efficient that many join fetch ( cartesian product + distinct ). ?

In my first impressions ( not tested with metrics ), "all eager fetch" strategy seems to be more efficient than only fetch required collections.

Can you confirm my observations ?

To finish, wake up the Lazy collection (by getting size() of Collection) is a very weak solution.

In case of millions entities, you will get a request for each collection to fetch of each object !

So ... "Eager fetch all strategy" Or "Fetch Join strategy" for ObjectDb ?

Regards,

Xirt

#2

> Is an "All eager strategy" more efficient that many join fetch (cartesian product + distinct)?

> So ... "Eager fetch all strategy" Or "Fetch Join strategy" for ObjectDb ?

All eager strategy may be faster, but may also consume too much RAM and becomes slow.

Unfortunately there is no one best solution for every situation, so you will have to test these options in your specific scenario to tune your application for maximum performance.

ObjectDB Support
#3

I'm afraid you are right ...

The best solution should to have the possibility to choose which collections to choose when retrieving entities into base.

Doest it exist a way to do that in JPA / JDO / something else ?

 

#4

Actually you can specify specific fetch paths for specific operations using JDO fetch groups, which are fully supported by ObjectDB but not documented (you can find more details in the JDO specification).

This ability became available also in JPA 2.1 (as entity graphs) but ObjectDB doesn't support it yet. It may probably be added in the near future because the underlying mechanism is similar to JDO fetch groups that are supported.

ObjectDB Support

Reply