简体   繁体   English

MappingException的原因:无持久性:MyClassProxy

[英]Reason for MappingException: No persister for: MyClassProxy

In a SaveOrUpdate call I'm getting the MappingException No persister for: MyClassProxy . SaveOrUpdate调用中,我得到了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 使用NHibernate版本3.3.1.4000
  • the mapping is created by code (not fluent) and in another dll that is referenced 映射是通过代码 (不是流利的)并在另一个引用的dll中创建
  • the mapping consists of a ClassMapping and a SubclassMapping with a discriminator 该映射由一个ClassMapping和一个带有区分ClassMappingSubclassMapping组成

I had this same exact issue. 我有同样的问题。 Basically I implemented a NHibernate.EmptyInterceptor to support INotifyPropertyChanged notifications. 基本上,我实现了NHibernate.EmptyInterceptor以支持INotifyPropertyChanged通知。

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. 但是我在线使用的示例错过了1个关键步骤……它没有覆盖GetEntityName方法,因此代理将被“转换”回实际对象。

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 源答案: 持久存在与NH Session不相关的Castle DynamicProxy

Note: the example used "Castle.Proxies" I did not use this and deleted this condition from the if block 注意:该示例使用了“ Castle.Proxies”,我没有使用它,而是从if块中删除了此条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM