NHibernate Interceptor - OnFlushDirty
<p>What I want to do is to intercept entity on save and truncate some string properties.</p>

<p>The issues is that <code>OnSave()</code> triggers only for new <code>Entity</code>, but not on changing/updating <code>Entity</code>.</p>

<p>Then there is <code>OnFlushDirty()</code> interceptor. But I am really confused with this one. </p>

<p>So I want to modify some property of entity on updating entity, like:</p>

<pre><code>public bool OnFlushDirty( 
             object entity, 
             object id, 
             object[] currentState, 
             object[] previousState,  
             string[] propertyNames, 
             IType[] types)
{
      bool entityChanged = false;
      for (int i = 0; i &lt; propertyNames.Length; i++)
      {
            var stringType = types[i] as NHibernate.Type.StringType;

            if (stringType != null)
            {
                 if(NeedTruncate(currentState[i]))
                 {
                      currentState[i] = Truncate(currentState[i]);
                      entityChanged = true;
                 }
            }
      }

      return entityChanged;
}
</code></pre>

<p>So the issue is next. On some blogs like <a href="https://www.targetprocess.com/blog/2006/08/entity-life-cycle-in-nhibernate/" rel="nofollow noreferrer">this one</a> I read that <code>OnFlushDirty()</code> is called when entity was changed and saved into database, so the changes to any property here will not be saved into database.</p>

<p>But in <a href="http://mausch.github.io/nhibernate-3.2.0GA/html/c3c18926-d5a8-3b22-d113-d495bd20b52e.htm#seeAlsoToggle" rel="nofollow noreferrer">githab.io</a> documentation it says: </p>

<blockquote>
  <p>The interceptor may modify the detected currentState, which will be
  propagated to both the database and the persistent object. Note that
  all flushes end in an actual synchronization with the database, in
  which as the new currentState will be propagated to the object, but
  not necessarily (immediately) to the database. It is strongly
  recommended that the interceptor not modify the previousState.</p>
</blockquote>

<p>It also says:</p>

<blockquote>
  <p>Called when an object is detected to be dirty, during a flush.</p>
</blockquote>

<p>So I am not sure what exactly means </p>

<blockquote>
  <p>Called when an object is detected to be dirty</p>
</blockquote>

<p>Also regarding to this documentation, the changes will be saved into database, just not necessary immediately.</p>

<p>Anyway, by testing this in my project, this works and when <code>OnFlushDirty()</code> is called and it changes value of some property it's also saved in database and all seams to be working fine.</p>

<p>So my question is: Is this correct to do? As I said, I tested it with my project and on changing/updating entity <code>OnFlushDirty()</code> is called, property is changed and saved into database as well. 
Just because all of this, and weak documentation, I am not sure if I can run into some issues with this?</p>