Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Rep Power

    Default hibernate association fetch

    what is the difference between eager and lazy fetching in hibernate and in which scenario we use which one actually i m generally take the default association ....................give me some suggestion

  2. #2
    Join Date
    Dec 2010
    Rep Power


    There is no easy answer to this because many factors are to be considered in this regards. I will try to explain this in a summarized way for now and come back to you with a detailed answer in a day when I have spent time to compile the answer with right examples.

    Try using eager loading, if there are few collection in the object you are loading. Eager loading will load all the objects at the very first call and many SQL queries will be fired. If the collection map and data in those rows are many, this will be slow.

    If your situation is such, I will recommend placing some selective collections for lazy loading. the biggest problem with lazy loading comes if the data has to be accessed across sessions like in a web application, where a UI layer will ask for data from a service and hold it in session and try to access the 'lazy collection' in a future session call. Because the collection has not been loaded, it will throw an exception and hence the UI has to handle the details correctly.

    To improve performance, you can actually use 2nd level cache in hibernate to overcome the issues with eager loading problems, but again choice is not that simple. If you have a concrete situation, I can provide a recommendation

Similar Threads

  1. association vs composition vs aggreagation
    By waqar100 in forum New To Java
    Replies: 2
    Last Post: 06-10-2010, 11:17 PM
  2. Difficulties with many-to-many association
    By berlindutza in forum Web Frameworks
    Replies: 0
    Last Post: 03-03-2010, 05:53 PM
  3. Replies: 1
    Last Post: 11-07-2008, 06:49 PM
  4. UML association,aggregation etc generator
    By alexander.s in forum New To Java
    Replies: 1
    Last Post: 09-18-2008, 07:27 PM
  5. Replies: 1
    Last Post: 07-06-2007, 07:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts