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

  • Home
  • SEARCH
  • 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 8854483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:53:27+00:00 2026-06-14T13:53:27+00:00

I am looking for help on an issue with NHibernate which has been bugging

  • 0

I am looking for help on an issue with NHibernate which has been bugging me for a while now. Long story short:

I’m looking for a way to, in the first level cache, “reset” a property on an entity each time I do an update or an insert.

What I want to achieve is that the property in question will always be considered to be dirty by NHibernate when using dynamic update or insert.

The backstory for this is that I know that, if the transaction was successful, the column that I want to “reset” will be set to Null in the database by a trigger. On the flip side, the first level cache does not know this, and thus NHibernate will think that the property was not updated when I set it to the same value as I did on the previous update/insert. The catch is that my trigger is dependent on this value being set. The resulting mess is that if I want to use dynamic update or insert I’m only able to update/insert an entity once without “refreshing” it afterwards (which I really don’t want to do).

Tips or help would be much appreciated, because I’ve really hit a wall 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-06-14T13:53:29+00:00Added an answer on June 14, 2026 at 1:53 pm

    NHibernate provides many places for extension. Among them is the Session IInterceptor. There is documentation with many details:

    http://nhibernate.info/doc/nh/en/index.html#objectstate-interceptors

    In this case, we can create our custom one, which will be observing our entity (for example Client) and a property which must be updated every time (for example Code). So our implementation could look like this:

    public class MyInterceptor : EmptyInterceptor
    {
        public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            var result = new List<int>();
    
            // we do not care about other entities here
            if(!(entity is Client))
            {
                return null; 
            }
    
            var length = propertyNames.Length;
    
            // iterate all properties
            for(var i = 0; i < length; i++)
            {
                var areEqual = currentState[i].Equals(previousState[i]);
                var isResettingProperty = propertyNames[i] == "Code";
    
                if (!areEqual || isResettingProperty)
                {
                    result.Add(i); // the index of "Code" property will be added always
                }
            }
    
            return result.ToArray();
        }
    }
    

    NOTE: This is just an example! Apply your own logic for checking the dirty properties.

    And we have to wrap Session this way:

    var interceptor = new MyInterceptor()
    _configuration.SetInterceptor(interceptor);
    

    And this is it. While Client is marked as dynamic-update, the property Code will always be set as dirty

    <class name="Client" dynamic-update="true" ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for any advice/intuition/clues/answers on a permission issue that has been plaguing me
I have been looking for few days now to fix the issue of recurring
I'm looking for a peice of software which can help me debug issues on
I'm looking for help with my query below. which is never returning anything for
Thank you for looking at my issue, hopefully you can help me out as
I have a strange JQuery issue that I am looking for help with. I
Been wrapping my head around this problem for a while and looking for solutions
I'm looking once again for help from the collective. I created a site which
Looking for help with a tripple nested repeater logic issue I have. Background I
Probably a common issue, but I'm looking for help in both fixing and understanding

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.