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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:51:42+00:00 2026-05-17T22:51:42+00:00

Hi: I am confused about what is cached by the hibernate cache. From the

  • 0

Hi:
I am confused about what is cached by the hibernate cache.

From the docs, I know there are there types of cache in hibernate.

First-level:the transaction-level.
It seems that the entity to be persisted by a session are cached here.

Second-level cache: I really have no idea about this cache,from the api,it said this cache work at the sessionfactory level… I can not understand.

Query cache: This is easily understand for me(maybe I am wrong). It cache the query parameter along with the related entity.

This is all I know about the cache in hibernate.

Anyone can give me more details?

BTW,I am not good at the sql/jdbc work,so I also want to know how should I know about the sql/jdbc to learn more about hibernate(any docs?)? I do not want to be just a hibernate user since it is just a tool,what I want is learn something from this wonderful framwork. 🙂

  • 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-17T22:51:43+00:00Added an answer on May 17, 2026 at 10:51 pm

    First Level Cache

    This cache is enabled by default.
    When NHibernate is loading an entity by its unique id from the database then it is automatically put into the so called identity map. This identity map represents the first level cache.

    The life-time of the first level cache is coupled to the current session. As soon as the current session is closed the content of the respective first level cache is cleared. Once an entity is in the first level cache a subsequent operation that wants to load the very same entity inside the current session retrieves this entity from the cache and no roundtrip to the database is needed.

    One of the main reasons behind this entity map is to avoid the situation that two different instances in memory can represent the same database record (or entity).

    (adapted from NH FAQ)

    Second Level Cache

    This cache is above the single session scope cache. With this cache you save many roundtrips to the database, since the first time anyone in any session loads determined entity, it remains in the cache, so the next request (from any other session) will get it from the cache.

    To use L2 Cache you will need a cache provider, such as SysCache or Memcache. These guys will store the values of the cached entities as an array os strings hashed by the entity’s id. It’s important to note that it’s not the .net object that is cached, but only its values.

    It is said that it’s tied to the session factory because the cache will work for sessions created by determined session factory, so sessions created by different session factories will not share cache. Is the concept of a session factory clear to you?

    Query Cache

    This one is really simple, but there is a catch. It will cache the query and its parameters, but it will not cache the entities returned. It will only cache their Ids, so it only makes sense with L2 cache, because it contains the values associated to that Id.

    NHiernate’s FAQ entry about cache:

    https://web.archive.org/web/20110514214657/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/09/first-and-second-level-caching-in-nhibernate.aspx

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

Sidebar

Related Questions

I'm a little confused about the HTTP protocol, from what i know HTTP was
I am a bit confused about the purpose of Varnish and Rack-Cache for a
I am still confused about passing by ref. If I have a Cache object
In the Guava Library, I am confused about why Cache.asMap() is not consistent with
Confused about triggers: I have two types of records, 'L' library and 'N' normal.
Totally confused about the data types required here. I have this Linq statement: var
I am a little confused about how to build a LRU cache by using
Confused about this...So I have a button that when clicked reveals a hidden div.
I'm confused about how should I do a model that has some uploaded file,
I'm a bit confused about Eclipse release 3.8 It seems a bit like a

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.