/// <summary> 
		/// If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy
		/// and overwrite the registration of the old one. This breaks == and occurs only for
		/// "class" proxies rather than "interface" proxies. Also init the proxy to point to
		/// the given target implementation if necessary. 
		/// </summary>
		/// <param name="proxy">The proxy instance to be narrowed. </param>
		/// <param name="persister">The persister for the proxied entity. </param>
		/// <param name="key">The internal cache key for the proxied entity. </param>
		/// <param name="obj">(optional) the actual proxied entity instance. </param>
		/// <returns> An appropriately narrowed instance. </returns>
		public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj)
		{
			bool alreadyNarrow = persister.GetConcreteProxyClass(session.EntityMode).IsAssignableFrom(proxy.GetType());

			if (!alreadyNarrow)
			{
				if (ProxyWarnLog.IsWarnEnabled)
				{
					ProxyWarnLog.Warn("Narrowing proxy to " + persister.GetConcreteProxyClass(session.EntityMode) + " - this operation breaks ==");
				}

				if (obj != null)
				{
					proxiesByKey.Remove(key);
					return obj; //return the proxied object
				}
				else
				{
					proxy = (INHibernateProxy)persister.CreateProxy(key.Identifier, session);
					proxiesByKey[key] = proxy; //overwrite old proxy
					return proxy;
				}
			}
			else
			{
				if (obj != null)
				{
					proxy.HibernateLazyInitializer.SetImplementation(obj);
				}
				return proxy;
			}
		}