I have a proxy for a lazy entity which has been created in the session by loading a child entity. A subsequent fetch on the parent entity only returns the NH proxy. I need the actual instance to check the type (the entity has joined subclasses). I must be missing something, but I can’t find a way to do this. Session.Refresh(proxy) does not appear to help, nor does any flavour of HQL that I’ve tried.
Can anyone help?
To force a proxy to be fetched from the database, you can use the
NHibernateUtil.Initialize(proxy)method, or access a method/property of the proxy.To check if an object is initialized or not, you can use the
NHibernateUtil.IsInitialized(proxy)method.Update:
To remove an object from the session cache, use the
Session.Evict(obj)method.Info about
Evictand other methods for managing the session cache can be found in chapter 14.5 of the NHibernate docs.