Philipp M
Philipp M

Reputation: 1891

Reason for MappingException: No persister for: MyClassProxy

In a SaveOrUpdate call I'm getting the MappingException No persister for: MyClassProxy.

What's strange is that I am able to insert new rows with the code, but if that row exists and the repository tries to update it, I'm getting this exception.

After searching and reading a lot of questions about this exception, that didn't help me to find the reason for this, I'll ask myself: What possible reasons can lead to this exception, if the mapping works for reading / inserting data?

Some more information about my case:

Upvotes: 0

Views: 761

Answers (1)

Selwyn
Selwyn

Reputation: 3198

I had this same exact issue. Basically I implemented a NHibernate.EmptyInterceptor to support INotifyPropertyChanged notifications.

but the example I used online missed 1 key step... it didn't override the GetEntityName method so proxies would be 'converted' back to the actual objects.

public override string GetEntityName(object entity)
{
    Type type = entity.GetType();
    if (type.FullName.StartsWith("Castle.Proxies") &&
        type.FullName.EndsWith("Proxy"))
    {
        return type.BaseType.FullName;
    }
    return base.GetEntityName(entity);
}

Source answer: Persisting a Castle DynamicProxy that's not associated with a NH Session

Note: the example used "Castle.Proxies" I did not use this and deleted this condition from the if block

Upvotes: 1

Related Questions