简体   繁体   中英

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:

  • using NHibernate version 3.3.1.4000
  • the mapping is created by code (not fluent) and in another dll that is referenced
  • the mapping consists of a ClassMapping and a SubclassMapping with a discriminator

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM