分享到: 百度 更多

项目中NHibernate问题及解决方法

 

 1.用户代码未处理 NHibernate.QueryException
  Message=Type mismatch in NHibernate.Criterion.SimpleExpression: PPPPortfolioGUID expected type System.String, actual type DecoratorAopProxy_58a5990eecd14c80ac61500fb1f1321f
  Source=NHibernate
QueryException  在查询的时候出错,但是查询条件检查没错,从字面上是类型不一致
  原来:<many-to-one column="PPP_PortfolioGUID" name="PPPPortfolioGUID" /> 
 修改:
 <many-to-one column="PPP_PortfolioGUID" name="PPPPortfolioGUID" class="IDST.Entity.Tables.PTPortfolioArchivedEntity,IDST.Entity" />
 
  nhibernate 使用hql语言进行查询操作,其执行的查询是对象的相关信息,而在nhibernate中,对象的属性是由.hb.xml来定义,故其查询的属性需与hb.xml文件定义字段相一致,包括大小写,如,Isession.CreateQuery(“select c.cusID  from customer c"),其cusID需与hb.xml中定义的一致
 
2.
"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. 
 
            待续 
 
待续。。
posted @ 2014-04-03 21:28  黑马_Summer  阅读(639)  评论(0编辑  收藏  举报
分享到: 百度 更多