Thursday, 26 September 2013

Hibernate Fetching Strategies

Advertisement

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 :
  1. join fetching(fetch="join") : In this case Hibernate will retrieves all the information in a single select statement.

  2. 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".

  3. 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";

  4. 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.

  5. immediate fetching(lazy="false") ; Hibernate will load all the associated child collection with the parent.

  6. 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).

  7. 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.

proxy fetching, No-proxy, Lazy attribute fetching these 3 are also the fetching strategies that is rarely used. Mostly these three are used in lazy applications.


    EmoticonEmoticon