No Persister for:使用INotifyPropertyChanged拦截器保存时出错

时间:2009-09-10 03:07:27

标签: nhibernate fluent-nhibernate

使用NHibernate & INotifyPropertyChanged中描述的方法,存储库将返回实现INotifyPropertyChanged的代理集合,但在保存或删除某些对象时会抛出错误:

   at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
   at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj)
   at NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session)
   at NHibernate.Event.Default.AbstractSaveEventListener.GetEntityState(Object entity, String entityName, EntityEntry entry, ISessionImplementor source)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
   at MyCode ...

我想通知如果我创建没有拦截器的会话,SaveOrUpdate工作正常,但是拦截器就会出错。

拦截器:

 public ISession GetSession(ISessionFactory factory)
        {
            IInterceptor dataBinding = new DataBindingInterceptor {SessionFactory = factory};
            return factory.OpenSession(dataBinding);
        }

 public ISession GetSession(ISessionFactory factory)
        {
            return factory.OpenSession();
        }

我对如何解决为什么拦截器会破坏豁免感到茫然。

我对代码所做的唯一更改是更改行

Type type = Type.GetType(clazz);

Type type = FindType(clazz);

public Type FindType(string typeName)
{
    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
    {
        Type foundType = assembly.GetType(typeName);

        if (foundType != null)
            return foundType;
    }
    return null;
}

1 个答案:

答案 0 :(得分:0)

解决方案是始终使用与拦截器的会话。我正在使用拦截器创建IList,但使用通用会话进行保存。这绕过了GetEntityName覆盖,它将代理重定向到正确的持久性。