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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:58:07+00:00 2026-06-18T10:58:07+00:00

I am using criteria to query the database based on the unique key. But

  • 0

I am using criteria to query the database based on the unique key. But I am coming through a weird scenario. After two or three queries, it starts giving me timeout expired error.

using (NHibernate.ISession session = m_SessionFactory.OpenSession())
{
  using (ITransaction transacion = session.BeginTransaction())
  {
    if (cashActivity.ActivityState == ApplicationConstants.TaxLotState.Deleted ||        cashActivity.ActivityState == ApplicationConstants.TaxLotState.Updated)
     {
       IList<CashActivity> lsCActivity = RetrieveEquals<CashActivity>("UniqueKey",cashActivity.UniqueKey);
       if (lsCActivity != null && lsCActivity.Count > 0)
       cashActivity.CashActivityID = lsCActivity[0].CashActivityID;
     }

     if (cashActivity.ActivityState == ApplicationConstants.TaxLotState.Deleted)
     {
       session.Delete(cashActivity);
     }
     else
       session.SaveOrUpdate(cashActivity);
   }
  }
}

  public IList<T> RetrieveEquals<T>(string propertyName, object propertyValue)
  {
     using (Isession session = m_SessionFactory.OpenSession())
     {
         Icriteria criteria = session.CreateCriteria(typeof(T));
         criteria.Add(Restrictions.Eq(propertyName, PropertyValue));

         IList<T> matchingObjects = criteria.List<T>();

         return matchingObjects;
     }
  }

I made changes in the code and start using StateLess Session but that change only reduces the frequency of timeout error.

After decugging , I found IList matchingObjects = criteria.List(); is cause of the exception. But this is only returning only one value, so it should not result timeout error since table also doesnt contain more than 100 rows as of now. Any Suggestions??

  • 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-18T10:58:09+00:00Added an answer on June 18, 2026 at 10:58 am

    Unless you have wrapped NHibernate’s ISessionFactory in something else, each call to OpenSession() will yield a new session. So the above code involves multiple sessions and it isn’t clear if this is required.

    Theoretically, a query on the session in RetrieveEquals() could block because of locks taken on the connection used in the calling method. But given the code as shown I can’t see anything to prove this.

    The calling method first updates a property of cashActivity, then in some cases goes on to delete the object. And there is no Commit(). This seems strange – is this really the used code or might there be a copy/paste error?

    You also say “after two or three queries”… do you imply that there is a loop somewhere which isn’t shown?

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

Sidebar

Related Questions

I'm using NHibernate to retrieve a list from the database based on some criteria.
I'm using NHibernate to query my database with the criteria API. My criteria is
How would I go about executing the following Hibernate query using the criteria API.
when using document's id as the only criteria in my query what's the difference
I'm trying to retrieve data from database using criteriabuilder. It's working great, query is
We are using Filter Criteria's to retrieve values from Storage Database (SQL Server). To
I'm using Nhibernate 3.2, Firebird Net Provider 2.7 and Criteria. after googled to how
I am using MySQL database. When I execute a query which the main table(20
Using JPA2.0 (via Hibernate 4), I can query the database for a record where
how can we get distinct result by using criteria in hibernate.

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.