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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:34:10+00:00 2026-05-12T22:34:10+00:00

Background Similar to this question , I need to determine if an entity in

  • 0

Background

Similar to this question, I need to determine if an entity in my NHibernate application is dirty or not. There is a “IsDirty” method on ISession, but I want to check a specific entity, not the whole session.

This post on nhibernate.info describes a method of checking an entity by fetching its database state and comparing it to the current state of the entity.

Problem

I’ve copied that method, but it isn’t working for me. See the code:

public static Boolean IsDirtyEntity(this ISession session, Object entity)
{
    String className = NHibernateProxyHelper.GuessClass(entity).FullName;
    ISessionImplementor sessionImpl = session.GetSessionImplementation();
    IPersistenceContext persistenceContext = sessionImpl.PersistenceContext;
    IEntityPersister persister = sessionImpl.Factory.GetEntityPersister(className);
    EntityEntry oldEntry = sessionImpl.PersistenceContext.GetEntry(entity);


    if ((oldEntry == null) && (entity is INHibernateProxy))
    {
        INHibernateProxy proxy = entity as INHibernateProxy;
        Object obj = sessionImpl.PersistenceContext.Unproxy(proxy);
        oldEntry = sessionImpl.PersistenceContext.GetEntry(obj);
    }

    Object [] oldState = oldEntry.LoadedState;
    Object [] currentState = persister.GetPropertyValues(entity, sessionImpl.EntityMode);
    Int32 [] dirtyProps = persister.FindDirty(currentState, oldState, entity, sessionImpl);

    return (dirtyProps != null);
}

The line that that populates the currentState array by calling persister.GetPropertyValues() is the problem. The array is full of nulls, instead of the actual values from my entity.

When I stepped into the code, I found that reflection is being used to get the values from the fields — but the fields are null. This seems like a result of the proxy, but I’m not quite sure where to go from 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-12T22:34:11+00:00Added an answer on May 12, 2026 at 10:34 pm

    I changed my default-access strategy from “field.camelcase-underscore” to “property” and now the persister.GetPropertyValues() method returns correct values.

    Too early to declare victory, but seems interesting. I was using the field access strategy because I had code in my entities’ properties to track dirty state. Since I’m removing that code and going to rely on NH to determine dirty state, I was able to use the property access strategy.

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

Sidebar

Related Questions

That's a question really similar to this previous post of mine. I need to
I'm implementing background fetching similar to this example . However, I also need to
My question is similar to this one: need to call soap ws without wsdl
Background I admit, this question stems from an ultimate lack of deep understanding of
Background: I'm writing a 'standard' (nothing special) web application in Ruby (not Rails) and
Question Summary: Is there a better method than the one posted below to implement
Background: I am aware of this SO question about Transactional NTFS (TxF) and this
OK some background. I have something similar to this: class ConnectionFactory { public IConnection
I have achieved something similar for particular items within my ListView in this question.
Background: I have a JSF 2.0 application using MyFaces. Using this application, the users

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.