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

  • Home
  • SEARCH
  • 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 565121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:50:19+00:00 2026-05-13T12:50:19+00:00

I started switching some pre-existing nHibernate code in a Sharepoint-based ASP.NET project from eager

  • 0

I started switching some pre-existing nHibernate code in a Sharepoint-based ASP.NET project from eager loading and a new session every database hit, to lazy loading and a session for the duration of the HTTP request, and started running into a problem.

When we create an Item in this system, there are some many-to-one relationships that are populated by dropdowns. That gets us the ID, which is enough to save to the database.

In order to perform some post-save tasks like email notification, we then load that same item back, which previously would get us the entire object tree populated.

However, since the change to lazy loading and a session with the lifetime of the entire request, we’ve been getting NullReferenceExceptions from properties below Item that are mysteriously null.

We load the item through nHibernate into changedItem. The call that’s failing is:

changedItem.PaperMedia.FormsAnalyst.User.Contact.Name

PaperMedia is fully populated, but everything on FormsAnalyst is null except the ID.

This is the same state as when we saved it, so one possible cause of this problem is the Item being cached and simply retrieved, nHibernate thus being ignorant of the actual values from the database. However, I’m committing the transaction, plus explicitly calling Flush() on the session, between the save and the subsequent load, so if that’s the case, neither Commit() nor Flush() is not having any effect on the cache.

I have changed these properties in the relevant hbm.xml files to be lazy=”false”, and have SetFetchMode FetchMode.Eager for all of them as well, to no effect.

I was also considering max_fetch_depth as the issue. If I call Refresh(changedItem) on the session, it has no effect. However, if I call Refresh(changedItem.PaperMedia), it will populate all the way down to Name. This would seem to discount max_fetch_depth as the problem, but I’ve nonetheless made an attempt to increase it, setting it to 6 in the hibernate.cfg.xml as well as SetProperty(“max_fetch_depth”, “6”) on the configuration instance while creating the session factory, and these have had no effect either.

I don’t know what else to try.

Anyone seen anything like that before? I’m new to nHibernate so it might be something simple…

Edit:

It would seem that caching is indeed the issue. Calling Clear() on the session instance fixes this behavior.

So the question now becomes, why would Flush() not update the cached items? That’s exactly what I thought it was built to do.

  • 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-13T12:50:19+00:00Added an answer on May 13, 2026 at 12:50 pm

    I think that Flush() is only for sending changes to the database… it would update the cache with the referenced objects if they were in memory at this time. So, you could either use another session or Clear()… or populate FormsAnalyst in the first place.

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

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Rename your Atempt2.java to Hello.java to get going, then: javac… May 13, 2026 at 8:46 pm
  • Editorial Team
    Editorial Team added an answer It looks like you're sending your coords in the query… May 13, 2026 at 8:46 pm
  • Editorial Team
    Editorial Team added an answer The XML file is probably in the ClickOnce data directory… May 13, 2026 at 8:46 pm

Related Questions

In some cases I've been using a DataTable, filtering it witha DataView and displaying
I am planning to write an simple 3d(isometric view) game in Java using jMonkeyEngine
I started iPhone development two months ago, so I can't call myself expert ;-)
I have been learning ASP.NET MVC in the last few months and I think
I've got a lot of mysql data that I need to generate reports from.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.