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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:09:26+00:00 2026-05-13T13:09:26+00:00

My problem is that NHibernate gets exponentially slow when fetching records from the database.

  • 0

My problem is that NHibernate gets exponentially slow when fetching records from the database. I had a request to basically pull all the data from a very large database to be used in a report.

I figured, well since I can’t get all the records in one shot because the recordset is so large, i thought try breaking it up. Basically I’m iterating through ranges of an index, ie. records id x to y, then y+1 to z, and so forth.

Each result set is about 10megs. The first 20 or so pulls takes less than a minute each, then on the next pull, it takes 10minutes, then 30minutes, and 1hr. I stopped the program there, didn’t want to wait till the next pull will come. I ran the program again starting from the index where I left off, again, the first 20 or so pulls are really quick, then for some odd reason there is a major slowdown.

Any help would be greatly appreciated.

  • 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-13T13:09:27+00:00Added an answer on May 13, 2026 at 1:09 pm

    NHibernate is doing a lot of work for you, and that might be slowing it down. It keeps objects you’ve pulled from in the session, which is basically a first level cache. When you run queries, it will check that set of objects to see if they need to be flushed back to the database (maybe you’ve changed them so that they now qualify as the result of the query!). So one strong possibility is that your query is secretly walking through a huge number of objects trying to figure out what it should write to the database before it ever sends your query to the database.

    If this is the case, you can try a periodic session.Clear() or session.Evict(object) which removes objects from the cache, so that NH won’t try to make the database consistent with them. You can always reattach objects later if you want NH to “pay attention” to them.

    Edit: or use a stateless session. Here’s an example.

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

Sidebar

Related Questions

I have a problem in that I have switched my (working) multiple-database nhibernate solution
I have a class that is mapped to a table using NHibernate. The problem
Seems to be a problem that many people have, but all the answers I
In NHibernate Profiler I observed that when I use eager fetching on an association,
I have a code which gets the date from Database from which I took
Here i am facing a problem that , i configured the hibernate sessionfactory in
Simple problem that I can't figure out... How can I print a '%' character
The problem that I have is somehow very specific. I have to implement a
I have a problem that I'm working on for quite some time now. I
Here is a problem that has been bothering me a lot about Python, I

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.