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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:15:17+00:00 2026-06-14T10:15:17+00:00

Having trouble with implementing second level cache in Nhibernate. I have a class mapped

  • 0

Having trouble with implementing second level cache in Nhibernate. I have a class mapped as follows:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data" namespace="Data">
   <class name="Account" table="Accounts" lazy="false">
     <cache region="Standard" usage="read-write" include="all"/>
     <id column="ID" name="ID">
       <generator class="assigned" />
     </id>
     <version name="VersionStamp" column="VersionStamp" type="integer" unsaved-value="0" />
     <property name="Name" not-null="true" />
     <property name="Type" not-null="true" />
     <property name="ClientID" not-null="true" insert="false" update="false" />
     <property name="DateCreated" not-null="true" type="UtcDateTime" />
     <property name="LastUpdatedDate" not-null="true" type="UtcDateTime" />
     <property name="IsActive" not-null="true" />
     <many-to-one name="Client" class="Client" column="ClientID" not-found="exception" not-null="true" />
   </class>
 </hibernate-mapping>

The property “ClientID” is a foreign key into the Clients table and the Client many-to-one property uses it to look up the associated client object.

When I add a new Account, I look up the Client object from the database with a Session.Get and assign it to my Account object’s Client property. Behind the scenes, this also automatically populates the ClientID property when the object is written to the database, and the ID is correctly stored in the database. When I retrieve the Account object from the database by ID using Session.Get, all the fields are populated correctly when the object is retrieved.

However, when I implement the second level cache using the settings shown above, the ClientID property is NOT populated when the Account object is retrieved using Session.Get, but the Client property is populated correctly. Is there some reason why this will not work with second level cache? Or have I done something wrong in my mapping/configuration?

For now I am just using SysCache as my caching provider, and both query and second level cache are turned on. The Client class mapping contains a corresponding one-to-many property for the Accounts.

I like the convenience of having the ClientID property on my Account class, so that I can read it without using the Client property, and it seems to work fine without caching.

Thanks for any help.

Rich

  • 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-14T10:15:19+00:00Added an answer on June 14, 2026 at 10:15 am

    I tried to reproduce your situation locally. With your mapping (used the same as the snippet above) I was able to get incorrect behaviour only on UPDATE. In that case, the ClientID was cached, and while the Client reference was changed, the ClientID remained unchanged. In other cases caching was working as expected.

    The solution is to change the mapping. The below suggested mapping is the most suitable for read-only properties like ClientID. (I am using that approach as well).

    <property name="ClientID" formula="[ClientId]" 
            not-null="true" insert="false" update="false" />
    

    So the trick is in the formula mapping instead of Column (the default when none is provided)

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

Sidebar

Related Questions

I have a small class hierarchy that I'm having trouble implementing copyWithZone: for. I've
I am having trouble implementing a sort. I have an XML document that I
I'm having trouble implementing a nested class who's constructor is initialized with some of
I am having trouble implementing image rotation in CUDA. I have a very simple
I have a C# MVC3 project and am having trouble implementing the HTML.CheckBoxFor. I
Im having trouble with implementing list view inside a fragment. the xml code is:
I'm having trouble implementing this. From other questions I have the following snippet: jQuery.expr[:].Contains
I'm having trouble implementing a functionality on my c#/asp.net app. I have a form
I'm having trouble implementing the Facebook SDK in an iOS project and I suspect
Problem: I am having trouble implementing a recursive image lazy load in all relevant

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.