I'm using lazy property in the object. 1) I need to load object without that property, detach it from the session. 2) Then I need to reattach this object to newly created session and load that property.
So, I am fetching data from the database (1) :
return session
.CreateCriteria<DataResource>()
.List<DataResource>()
.ToArray();
Than I'm trying to reattach it and fulfill (2):
using (ISession session = GetSessionFactory().OpenSession())
{
session.Update(dataResource);
NHibernateUtil.Initialize(dataResource.Value);
}
In case if laziness was on one-to-many link - all works ok. (1) step returns my real object, with a proxy set to that property, and after (2) step it become real object. But in case when I need laziness on the property, it seems that NHibernate cannot handle that with real object. Instead of that it returns proxy after step (1). Than in the step (2) it throw MappingException: No persister for: Castle.Proxies.DataResourceProxy on the .Update() line. Somehow it cannot recognise its own proxy.