Today i am going to tell you what are the Hibernate Fetching Strategies and how to use that in order to tune the performance of your applications.
So these are the fetching strategies in hibernate :
So these are the fetching strategies in hibernate :
- join fetching(fetch="join") : In this case Hibernate will retrieves all the information in a single select statement.
- select fetching(fetch="select") : Here the Hibernate will pass the second select statement for fetching the associated collection unless you disable lazy fetching by specifying lazy="false".
- subselect fetching(fetch="subselect") : Here in this case the collection will be fetched using subselect sql statement unless you explicitly disable lazy fetching using lazy="false";
- batch fetching(batch-size="") : As the name suggest if you want to customize the number of select statement you can use batch fetching. It can be configured on both class and collection label.
- immediate fetching(lazy="false") ; Hibernate will load all the associated child collection with the parent.
- lazy collection fetching(lazy="true") : here the associated collection will be loaded only when you use it or you can perform any operation on it(one of the best practice to tune the performance of your application).
- extra lazy : specific element of the collection is accessed as needed. Here in this case hibernate will not load the whole collection unless you tried. It is suitable for large collection.
EmoticonEmoticon