Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:20:31+00:00 2026-06-11T18:20:31+00:00

I believe there is only two ways of loading objects using Hibernate and that

  • 0

I believe there is only two ways of loading objects using Hibernate and that is lazy loading and one is eager loading. Lazy loading has its own advantages, it is not loading lots of objects but only when you need them. I also have learned that if you want to force to load all the children for an object you can simply call the parent.getChildren().size(). So let’s say we have the following objects

@Entity
public class Customer{
public Set<Order> order;
}

@Entity
public class Order{
}

let’s assume we have customers who has orders in our system and it might be more than one or even null. So my question is isn’t it better to always using eager loading in this case? we need the size or some information for the order related to the customer. What is the benefit of using lazy loading in this situation, is there any benefits?

I am trying to understand where to use lazy loading and where to use eager loading, highly appreciate your insight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:20:33+00:00Added an answer on June 11, 2026 at 6:20 pm

    I am trying to understand where to use lazy loading and where to use
    eager loading, highly appreciate your insight.

    Here are a few thoughts:

    1) If you are going to always use something (for sure), you can eager load it.
    2) Related to 1, if you are almost never going to use something, lazy load it.
    3) Lazy loading tends to be more useful when large collections are involved.
    4) Eagerly loading things will reduce session-related errors, at the potential cost of a performance hit.
    5) For complicated data models and/or large databases, you are going to see how your app does under load an adjust your strategies.
    6) It’s difficult to get it right the first time. Do what feels right, and don’t be afraid to change if necessary.
    7) For large datasets, you are going to probably end up writing custom hql/queries anyway, where the default mappings can be overwritten, so lazy vs eager won’t matter so much.

    If you believe #6, then don’t get stuck trying to plan too far ahead, and change it if you have to.

    WRT your specific example, I would probably write a bunch of queries to access the data (driven by appropriate business needs, of course)

    1) A query that loads the customer, and leaves the orders in the db (so lazy loading) that I would call when I need to get customer info
    2) A query that loads the customer and all order info, for cases where I need it. So this case I’ll ignore the default mapping.

    With those two queries in place, in my service layers I have the tools I need to do what is correct based on the context of the situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although there are a lot of posts about .net config files, I believe that
I found an example of lazy loading, and I believe I have implemented it
I am attempting to send an email using VB.NET. There are two requirements: The
I have four NSTimers that work fine. The only problem is that two should
I can't believe I'm asking this but, is there any way to get Chrome
All, there are many question on the above topic but I believe this is
In the UK throughout the 80's and 90's (70's too I believe!) there was
I believe I am using the correct queryString params for jdbc connection jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8&noAccessToProcedureBodies=true My
I believe that the rallytagpicker is definitely a useful component. However, I do not
I believe I am having a security problem related to using the embed tag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.