Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate throwing "Unable to resolve property:", but property doesn't exist *ANYWHERE* in project

I'm getting a weird issue with nHibernate... I'm getting this exception:

Unable to resolve property: _Portal

when I try to commit an object graph. The strange thing is that when I search through the entire solution, I don't seem to have this particular property ANYWHERE within the project?!

Has anyone run into this particular case, and if so, what did they do to resolve?

like image 910
Richard B Avatar asked Feb 21 '23 14:02

Richard B


2 Answers

I've ran into the same issue after upgrading nHibernate to 3.3 (from 3.1), as well as associated libraries (including FluentNhibernate). I have a parent object with a child collection, and when modifying the child collection, it would throw the same exception you received (with the nonexistant "_Namespace" property name, where "Namespace" was the first section of my actual namespace).

In our case, switching to SaveOrUpdate() is not an option, as we actually have a version of this object loaded in session as well, so we need Merge().

I don't know what other similarities there might be. For us it's a parent object with a child collection, using FluentNhibernate. Mapping on the parent object is Cascade.AllDeleteOrphan() for the child, and for the child to the parent, Cascade.None().

Unfortunately I can't find any other reports of this bug, so the solution for us was to just revert back to nHibernate 3.1 (and the associated binaries, like FluentNhibernate and Iesi.Collections). That's the only change, and then it works fine again.

Update on bug logged in JIRA [3234].

There is a bug logged for this in JIRA. The issue has not received any priority yet. Perhaps if you are experiencing this issue you can create an account and vote for the bug to be fixed. https://nhibernate.jira.com/browse/NH-3234

Update on workaround posted for bug JIRA [3234].

As per Ondrej's comment on the bug, overriding the default merge listener on the session configuration with this code solves the issue for now. I am sure with the workaround posted it will be fixed officially soon.

public class UniDirectionalMergeFixListener : DefaultMergeEventListener
{
    protected override IDictionary GetMergeMap(object anything)
    {
        var cache = (EventCache)anything;
        var result = IdentityMap.Instantiate(cache.Count);

        foreach (DictionaryEntry entry in cache)
            result[entry.Value] = entry.Key;

        return result;
    }
}
like image 193
Robert Avatar answered Mar 08 '23 23:03

Robert


So I solved my issue, but I'm not sure why this was the resolution.

In my project, I've abstracted out the use of nHibernate to be in its own project (*.Objects.nHibernate is the namespace). I did this because the client I work with doesnt' typically like using nHibernate, and I'm trying to get them onboard with using it.

What was happening is that this project has a few data models that are append only in the system... e.g., we never do an update. So, my "Repository" has to take that into account.

In my Commit() function within the repository, I serialize the object graph and then deserialize it to make a copy of the object for saving. What I was doing was saying to the session "_Session.Merge(...)", when I needed to say "_Session.SaveOrUpdate(...)" to get things to commit to the database properly... unsure why that made a difference, but that was the answer to the past two days.

Thx. for your help Rippo & Nickolay!

like image 42
Richard B Avatar answered Mar 08 '23 23:03

Richard B