NHibernate: uninitialized proxy passed to save() and cascade

Posted by jonnii on Stack Overflow See other posts from Stack Overflow or by jonnii
Published on 2008-10-15T16:34:35Z Indexed on 2010/05/29 20:12 UTC
Read the original article Hit count: 324

Filed under:
|

Hi,

I keep getting an NHibernate.PersistentObjectException when calling session.Save() which is due to an uninitialized proxy passed to save(). If I fiddle with my cascade settings I can make it go away, but then child objects aren't being saved.

The only other fix I have found is by adding the following to my DefaultSaveEventListener.

    protected override bool ReassociateIfUninitializedProxy(object obj, global::NHibernate.Engine.ISessionImplementor source)
    {
        if (!NHibernateUtil.IsInitialized(obj))
            NHibernateUtil.Initialize(obj);

        return base.ReassociateIfUninitializedProxy(obj, source);
    }

This is obviously not an ideal solution.

Any ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate