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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:26:14+00:00 2026-05-22T14:26:14+00:00

I am using NH 2.1.2.4. I have the query cache setup with Fluent NHibernate

  • 0

I am using NH 2.1.2.4.

I have the query cache setup with Fluent NHibernate like this:

MsSqlConfiguration.MsSql2005
    .Cache(c => c.UseQueryCache()
            .ProviderClass(typeof(NHibernate.Caches.SysCache2.SysCacheProvider)))

My criteria looks like this:

Session.CreateCriteria<Employee>()
    .Add(Restrictions.Eq("Username", username))
    .SetMaxResults(1)
    .SetCacheable(true)
    .UniqueResult<Employee>();

However, when I use SQL Profiler I can see the query is still always being executed against the database. No inserts or updates to the Employee table are being made.
Why is it not working?

My Employee mapping class specifies Employee as cachable like this:

public sealed class EmployeeDbMap : ClassMap<Employee>
{
    public EmployeeDbMap()
    {
        ....

        Cache.ReadWrite();
    }
} 

BTW I see there are a number of related questions on Stackoverflow, but none seem to have good answers: here and here.

  • 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-22T14:26:14+00:00Added an answer on May 22, 2026 at 2:26 pm

    If you are not caching the Employee entity too, a query will be needed to load it, as the query cache stores the results as ids.

    Also, NHibernate cache only works if you do all your work (including queries) inside transactions.

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

Sidebar

Related Questions

I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I have a query that searches for clients using like with wildcard. For example:
I have a database being used to cache entities. The tables looks like this:
I am using in C# MYsql .I have query that works if I run
I have a query that is currently using a correlated subquery to return the
I have a query that I know can be done using a subselect, but
I have a query that I am generating the XML from in Oracle using
We have the query below. Using a LEFT OUTER join takes 9 seconds to
Background: I'm using SQL Server Management Studio 2008 and I have a query window
I have been using the MySql Query Browser and [opinion]it has to be the

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.