Hibernate - should i fetch and how?

In  the top application bottlenecks we find issues regarding to the database area. When dealing with DB we need to plan well - the access and the fetching scope.

Since DB is the bottleneck hibernate, as a third party that work against the database, has a major impact on the application performance.
Lot of people look for a mystery configuration flag that will boost their "hibernate performance". I am sorry to disappoint you there isn't such flag. I search on all hibernate source code for an attribute name - "boost performance" and didn't find it. There are some hibernate configuration that can affect the application performance like batch size and etc , but don't hang up your hopes on those configurations.
If there is performance problem- they mostly hide in your application and not in hibernate global configuration.

In most cases either you load too much information or your current fetch plan is not the best choice.
Hibernate have some attributes which control on the data fetching.

The main two are:
1. Lazy - true/false
2. Fetch strategy - select,subselect,batch,join

The lazy - control on -"when" should I fetch the association now!!!! Immediately, with the association owner.
The fetch strategy control on "how"- should i load them in join with the owning entity? Should I load them in second select...
Obviously the attribute has some overlap. If you chose in fetch strategy join this means that you need to load them with the owning entity (the answer to the "when" is now).
So if the fetching is too slow - check the fetching plan - did you load too much information, did you have many db access? Should I change the plan?
Developers love to thing on magic solution- one solution for all problems. we told a lot of time that join is the best solution since it minimize the db access - so again sorry to disappoint you the answer is not- join is not the best answer for all situations (i will expand on this in the near future).

So now you need some details. as a java programmer I believe in reuse so I will give an excellent references.
http://www.mkyong.com/hibernate/hibernate-fetching-strategies-examples/
http://www.javalobby.org/java/forums/m91885142.html
http://community.jboss.org/wiki/AShortPrimerOnFetchingStrategies

אין תגובות:

הוסף רשומת תגובה