(1)Nhibernate错误”No persister for ”
Nhibernate错误”No persister for <entity name>”
例如:”No persister for DomainModel.Entities.User”
1.检查hibernate.cfg.xml是否配置mapping 如:<mapping assembly="”DomainModel”/">
2.检查User.hbm.xml文件属性“生成操作”的值,从“内容”修改为“嵌入的资源”
(2) Could not find the dialect in the configuration这个错误,
这是数据库配置问题
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
换成
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
(3)The ProxyFactoryFactory was not configured 报错
因为没有引用上面那个配置中的工厂类 所以在引用下 Required_For_LazyLoading文件夹下的 LinFu下的NHibernate.ByteCode.LinFu.dll 当然也可以用 Castle 那要改下配置</hibernate-mapping></hibernate-mapping>< /mapping></entity>
(4)、Could not compile the mapping document
解决办法:
调试查看到InnerText为,不应该为 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">,然后我把改为
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 后,此问题解决.
(5) NHibernate.InvalidProxyTypeException
The following types may not be used as proxies: TestCleanSnow.BjkptOaxtCleanupsnow: method set_IsDeleted should be virtual TestCleanSnow.BjkptOaxtCleanupsnow: method set_IsChanged should be virtual TestCleanSnow.BjkptOaxtCleanupsnow: method Clone should be virtual TestCleanSnow.BjkptOaxtCleanupsnow: method get_IsChanged should be virtual TestCleanSnow.BjkptOaxtCleanupsnow: method get_IsDeleted should be virtual
解决办法: 在XML的 <class name="TestCleanSnow.BjkptOaxtCleanupsnow,TestCleanSnow" table="B_JKPT_OAXT_CLEANUPSNOW"> 添加 lazy="false" .
(6)在执行 session.Save(cs);
时,出现 could not get next sequence value[SQL: SQL not available] Nhibernate
解决办法:
把相应XML的
<generator class="native" /> 改为 <generator class="assigned" />
以上我做Oracle时出现的错误,操作sqlserver的时候应该为 <generator class="native" /> .
(7)转载与: http://hi.baidu.com/zsea/blog/item/7d999e3d8a54c203baa1678d.html
一、Test.Model.Person.hbm.xml(2,2): XML validation error: 未能找到元素“urn:nhibernate-mapping-2.0:hibernate-mapping”的架构信息。
将2.0改为2.2
二、 The following types may not be used as proxies:
Test.Model.Person: method set_Id should be virtual
Test.Model.Person: method get_Name should be virtual
Test.Model.Person: method set_Name should be virtual
Test.Model.Person: method get_Id should be virtual
类配置文件中Class的Lazy改为false
网上搜到的三种解决方案:
1. You can follow the advice of the exception and add " virtual " to all of your properties, and make sure your class is non-sealed. Obviously you'll want to do this if you think you might want to take advantage of the lazy-initializing proxy feature. However, changing your classes may not be practical or advisable if you have a legacy codebase, or it may just bother you that a "transparent" persistence framework is dictating how you design certain aspects of your value classes. That's where Options 2 and 3 come in. Both of those involve changing back to the old behavior.
name="NorthwindClasses.Category, NorthwindClasses"
table="Categories"
lazy ="false"
>
-
hbm.xmlNHibernate文件中版本号可能引起的问题.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
此处的2.2代表了NHibernate的版本号,必须与你安装的NHibernate的产品版本号相符.否则的话,举个例子,若为 urn:nhibernate-mapping-2.0,则会出现如下错误: Could not find schema information for the element 'urn:nhibernate-mapping-2.0:hibernate-mapping'. 或是:"NHibernate.Cfg.Environment的类型初始值设定项引发异常". -
在对照类中如果属性没有加virtual关键字,可能报
NHibernate.InvalidProxyTypeException: The following types may not be used as proxies:
Model.FriendLink: method set_Description should be virtual
Model.Type: method get_TypeName should be virtual.....
这是一 种解决方案是给属性加上virtual关键字,另一种解决方法是在映射文件中加入default-lazy="false". -
in expected: <end-of-text> (possibly an invalid or unmapped class name was used in the query).
映射文件没有将属性设为"嵌入的资源"或者调方法时表名大小写问题
-
" Could not find the dialect in the configuration"异常
- 异常描述:
NHibernate.MappingException: Could not compile the mapping document: Model.FriendLink.hbm.xml ---> System.InvalidOperationException: Could not find the dialect in the configuration
在 NHibernate.Dialect.Dialect.GetDialect(IDictionary`2 props)
在 NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
解 决方法:配置文件中xmlns = "urn:nhibernate-configuration-2.2 " 千万不能忘记,确保没有忘掉xmlns = "urn:nhibernate-configuration-2.2 " 就可以解决这个bug.
另参见:http://blog.csdn.net/lateknow/archive/2009/12/02/4924856.aspx