title: NHibernate warning Narrowing proxy to - this operation breaks ==
body: <p>I have a question about about proxy in NHibernate. I've inside in my log file a lot of logs like: Narrowing proxy to - this operation breaks ==
  There are a few other questions on the web and different answer:</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/8267915/nhibernate-narrowing-proxy-warning">Stackoverflow NHibernate narrowing proxy warning</a> <strong>It being a big deal or not depends on the level of risk you are willing to accept.</strong> Since there is going to always been a disconnect between your code and your database you can not always assure that the casting will work. <strong>This will lead to bugs that might be difficult to diagnose and may not be resolved without changes to the database or the code.</strong></p>
  </blockquote>
  
  <p>Another post from hibernate:</p>
  
  <blockquote>
    <p><a href="https://forum.hibernate.org/viewtopic.php?p=2404391" rel="nofollow noreferrer">Narrowing problem</a> <strong>Don't worry about his warning</strong>, just put the following in your log file and you shouldn't see it anymore...</p>
    
    <p>Why it happens? 
    Suppose you have a Product with a many-to-one association to Address. Both are entities and Address has a ShippingAddress subclass. </p>
    
    <p>Let's Session.get(..) a Product from the db that has ShippingAddress as association. Because the many-to-one is lazy, it will return a Address proxy. Note that this is a Address proxy and not a ShippingAddress proxy as the proxy will always match the type that is mentioned in Product (see the hibernate book for details). </p>
    
    <p>This proxy is stored by Hibernate in his proxy cache. 
    Now we Session.get(...) the same ShippingAddress from the db, the one that is associated to the Product that we used fetched from the db. 
    Now Hibernate will see that it already contains a proxy for this ShippingAddress and will return this. However, it will notice that the types aren't the same so a "downcasting" must occur. Because this latter action isn't possible with "proxies" it will create new one and return it... </p>
    
    <p><strong>As you can see, nothing to worry about.</strong> 
    You could consider making the Address a value type... 
    In my case that's no option. </p>
  </blockquote>
  
  <p>And a last one</p>
  
  <blockquote>
    <p><a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=1030440" rel="nofollow noreferrer">ProxyWarnLog Removed in Hibernate 4?</a></p>
  </blockquote>
  
  <p>Here is the code from NHibernate: <a href="https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Engine/StatefulPersistenceContext.cs" rel="nofollow noreferrer">StatefulPersistenceContext.cs -> NarrowProxy(..)</a></p>
  
  <p>So, is it a problem or not? I always work with detached objects in my program.
  I hope someone can help me.
  Thanks a lot.</p>