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 209095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:53:04+00:00 2026-05-11T17:53:04+00:00

Iam struggling with NHibernate and its lazyload. I have a structure which I simplified

  • 0

Iam struggling with NHibernate and its lazyload.

I have a structure which I simplified but it show my issue.

Class Shift {
 int ShiftID;
 DateTime ShiftStart;
 Employee Employee;
}

Class Employee {
 int EmployeeID;
 string Name;
}

Data:

 ShiftData
 ID                         SHIFTTIME       EmployeeID (int)
 1                           12:00                  0
 2                           13:00                  1
 3                           14:00                  0                           
 4                           13:00                  3


Employees
ID                         NAME
1                           Morten
2                           Peter
3                           Henrik

My loading strategy for the shift is using Join so that when I load the shifts NHibernate automatically does a Left join to get the customer.
This works perfectly for the shifts with Employees attached, however some shifts haven’t got any employees yet.

When I try to access the Employee of such a shift once the shift is loaded it results in another SELECT against the database (found out by using your NHProfiler)
Why does this happen ?

Hope you have an answer iam really stuck on this.

  • 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-05-11T17:53:05+00:00Added an answer on May 11, 2026 at 5:53 pm

    My guess is that this happens because shifts without employees will have an empty Employee proxy. NHibernate sees the empty proxy and dutifully tries to load the data from the database.

    As for the solution, seeing your mapping would really help. However, you might try ensuring that the relationship has the fetch=”join” attribute set or turning off lazy loading for this relationship.

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

Sidebar

Related Questions

I've crafted two queries which both work fine, but I am really struggling to
I have just started to use NHibernate 3.2 with its new Conformist API, having
I am struggling with linking ALAssetsLibrary in my code. I have googled a lot
I'm about to start developing a large-scale system and I'm struggling with which direction
I am struggling with a MYSQL query - I have 2 tables : Table
I am using ASP.NET-MVC and nHibernate for the first time. Great tools, but big
I'm really struggling to get my first NHibernate project off of the ground, I
I am struggling to understand a possible memory leak in my code. I have
I am struggling with maven in Eclipse even though I have m2e. I checked
I have a project where I'm using NHibernate to handle bindings to the database.

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.