Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Fetching Strategies in Hibernate

Join Fetching: In Join Fetching Hibernate fetches the associated instance and its collection in a single select using OUTER JOIN. If join fetching is enabled then lazy fetching should be disabled, instead fetch retrieves all the associations and collections associated with the instance.

          <set name="permissions"  fetch="join" >
               <key column="pId"/>
               <one-to-many class="Permissions"/>
          </set>
Fig: Join Fetch ( Click on the image to see clearly)
Select Fetching: In Select Fetching Hibernate fetches only the parent instance and lazily load the collections and associations.Lazy loading should be enabled and it doesn't allow immediate fetching.

Fig: Select Fetch(Click on image to see clearly)


<set name="permissions"  fetch="select" >
               <key column="pId"/>
               <one-to-many class="Permissions"/>
          </set>


Batch Fetch: In Batch Fetching Hibernate fetches set of instances and its associations by specifying list primary or foreign keys.  

<class name="ProjectSpecification">
   <set name="permissions" batch-size="10">
     <------------>
   </set>
</class>



                                                                                                          Vissu


This post first appeared on Java Spring Hibernate, please read the originial post: here

Share the post

Fetching Strategies in Hibernate

×

Subscribe to Java Spring Hibernate

Get updates delivered right to your inbox!

Thank you for your subscription

×