Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate: uninitialized proxy passed to save() and cascade

Tags:

c#

nhibernate

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?

like image 514
jonnii Avatar asked Oct 15 '08 16:10

jonnii


1 Answers

There mere presence of a custom DefaultSaveEventListener subclass containing no overidden or extended behaviour is enough to trigger this exception for me, using the following configuration Xml:

<event type="save-update">
    <listener class="MyNamespace.MyCustomSaveEventListener, MyAssembly" />
</event>

I am continuing this discussion in this question.

Update:

I had mistakenly derived from DefaultSaveEventListener instead of DefaultSaveOrUpdateEventListener, changing the superclass made this problem go away for me.

like image 112
Rabid Avatar answered Oct 28 '22 13:10

Rabid