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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:01:32+00:00 2026-05-13T10:01:32+00:00

In NHibernate Profiler I observed that when I use eager fetching on an association,

  • 0

In NHibernate Profiler I observed that when I use eager fetching on an association, using “left join fetch” in an HQL Query or .SetFetchMode() in a Criteria Query the query no longer gets cached in the query cache.

In fact from what I can see only very basic queries are cached. If anyone can give me some insight into what queries get cached and which ones don’t I will mark answer.

If it makes any difference, I’m using Memcached…. Is there a better choice for L2 Cache for a query-dense system?

I’m finding this rather challenging – if I don’t use eager load I have the N+1 problem (but uses cache), if I do eager load, I get all the entities from the database, but with no caching.

It seems like there is quite a thick dividing line, both strategies have performance improvements but both strategies rob performance from the other strategy.

If anyone can give any insight into where abouts on this ‘thick line’ I should be to have optimal performance, or how to ‘make the line thinner’… I would be very gateful and mark the answer.

  • 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-13T10:01:32+00:00Added an answer on May 13, 2026 at 10:01 am

    Update:
    Please see my related question here. the bottom line is, try using fetch=”select” to avoid joining with objects that are already in the 2nd level cache.


    My previous answer (may still be usefull)

    Query cache caches the identifiers returned from your query, not the actual objects

    To use it properly you should

    1. Use place holders (? or :varName)
    2. Set query cache to true (you did)
    3. The query should return objects, not properties (from Foo, not select foo.bar from Foo foo)
    4. The returned objects should be either in the 2nd level cache, or subsequent calls are in the same hibernate session (same transaction)

    To clarify #4, if 2 different transactions run the exact (cached) query with the exact parameters and returns the exact same object, but it is not in the 2nd level cache, a database hit will still occur to get the actual objects (probably a select .. in )

    Query cache is useful for 2 things – avoid re hitting the database in the same transaction for HQL queries for non cached items, and allow utilizing 2nd level cached objects for HQL queries (automatically used in load or get commands)

    Hope it cleared the forest…

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

Sidebar

Related Questions

I am using NHibernate and started using the NHibernate profiler and realized that I
We use the Fluent nHibernate repository model in a .net MVC project that I'm
I would like to profile my NHibernate queries that I run from LINQPad using
i am using nhibernate profiler and seeing a few places where it is giving
I am using NHIbernate against MySql, and when I use the following statement, NHibernate
I'm using NHProf with ASP.NET MVC 3. I inserted HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(); in my Application_Start method,
I have a basic MVC application that is using NHibernate for OR/M and data
I'm using discriminators to deal with item states. I'm using the NHibernate Profiler and
I've just downloaded nhibernate profiler and I cannot figure why it is not working.
NHibernate Version: 2.1 I'm using what seems to be a pretty standard HttpModule approach

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.