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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:15:47+00:00 2026-05-11T22:15:47+00:00

I’ve been getting some extremely bizarre behaviour where NHibernate queries start to hang. I’ve

  • 0

I’ve been getting some extremely bizarre behaviour where NHibernate queries start to hang. I’ve made a demo project that exhibits this behaviour in a repeatable fashion.

You can download the project here

Here’s the offending code:

    public IList<Post> GetLatestLiveBlogEntries(int numEntriesToRetrieve)
    {
        var maxDate = DateTime.Now;

        using (var session = SessionManager.OpenSession())
        {
            var crit = session.CreateCriteria(typeof (Post))
                .Add(Restrictions.Eq("Enabled", true))
                .Add(Restrictions.Lt("postDate", maxDate))
                .AddOrder(new Order("postDate", false))
                //.SetFetchMode("author", FetchMode.Eager) // <-- the exclusion of this line breaks everything!
                .SetMaxResults(numEntriesToRetrieve);

            StupidFileLogger.Log("If this is the last log, I'm hanging on crit.List<Post>()");
            var listOfPosts = crit.List<Post>();
            StupidFileLogger.Log("I actually was able to retrieve the posts");
            return listOfPosts;
        }
    }

The key line is the .SetFetchMode on the author field. On the first load of my demo project it loads fine. When I hit refresh, it hangs and never gets past the crit.List() call. With eager loading it works everytime.

I’m using Castle.Facilities.NHibernateIntegration.Components.SessionWebModule to ensure 1 session per request.

The other bizarre thing I’ve found is that this only happens with SQL Server. When I use SQLite everything works fine. In my demo project I have a simple build flag that allows you to switch db’s easily. Just look at local.properties.xml in the /build directory.

I understand that eager loading solves my issue in this particular case, but in my application I don’t want to have to eager load everything.

Please download the solution and try for yourself. I’ve tried it on other machines and they do the same thing.

Here are some SQL Profiler captures. You can see that the query for Posts was sent to the server, but it stops there:

First request (behaves as expected):

good request http://muc-central.com/misc/good_request.jpg

Second request (hangs):

alt text http://muc-central.com/misc/hanging_request.jpg

  • 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-11T22:15:47+00:00Added an answer on May 11, 2026 at 10:15 pm

    I fixed the hang by switching to the LinFu proxyfactory.factory_class. Have no idea why this works and Castle doesn’t. Going to learn more about Dynamic Proxies and figure out what kind of bug report I should submit.

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

Sidebar

Related Questions

No related questions found

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.