NHibernate 异常及解决办法(长期添加中)

Mapping 错误:

1) Could not determine type for:Namespance.Class,AssemblyName, for columns: NHibernate.Mapping.Column(ColumnName)

通常是Mapping中的 type attribute设定错误,在Assembly找不到。如

<property name="PropertyName" column="ColumnName" type="Namespance.Class,AssemblyName">

如果没有column , 那么就是 PropertyName作为ColumnName。

2)The following types may not be used as proxies:
Namespance.Class: method methodName should be 'public/protected virtual' or 'protected internal virtual'

Namespance.Class: type should not be sealed

类中的 public/protected 方法没有使用 virtual 修饰,加上virtual就可以了。因为NHibernate 对于Many-to-one的one方,采取了lazyLoad,因此在加载Many的时候,会为one这生成Proxy类,因此One不能是一个seald类,并且所有公开方法都需要使用virtual, 如Child的属性Parent,如果想获得Child的时候,不加载Parent数据,那么Parent必须符合以上的规则。

另外一种办法是,把one一段的对象设定为<class lazyLoad=false>

3)NHibernate.PropertyNotFoundException: Could not find a getter for property 'Id' in class 'Namespance.Class,AssemblyName'.

 找不到属性 Id的 getter,这个getter也可以换成为setter。 补充get 和 set,就可以解决。

4) These classes referenced by 'extends' were not found:

FullName:Namespace.class - Name:class

在继承映射中,如subclass ,需要一个Extends的 attribute,但是这个extends所指向的父类的名称,在mapping中并不存在。填写正确的 extends就可以。 

5) MappingException: An association from the table Crimson_Info refers to an unmapped class: Crimson.Contents.Content 

原文地址:https://www.cnblogs.com/fantasylu/p/1717324.html