Nhibernate一些问题解决方法

问题1.未能找到元素“urn:nhibernate-mapping-2.0:hibernate-mapping”的架构信息。 file:///c:/inetpub/wwwroot/WebApplication1/bin/Course.hbm.xml, (2, 2)处发生了错误。
解决办法:
一、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.

          2.  To change the lazy-initialization proxy setting for a specific class, you can add a "lazy='false'" attribute to the <class> mapping element.  This might look something like: <class
    name="NorthwindClasses.Category, NorthwindClasses"
    table="Categories"
    lazy="false"
>        3.  To change the lazy-initialization proxy setting for all classes in a given mapping file, you can add a "default-lazy='false'" attribute to the <hibernate-mapping> element, as follows: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-lazy="false"> Unfortunately, Option 3 doesn't really help you much if you do one <class> mapping per <hibernate-mapping> file, a practice which I personally follow and recommend.  It's too bad, but there doesn't seem to be any way to set this default in the <nhibernate> global configuration.  But if you do happen to have all of your <class>'s in one .hbm.xml file, "default-lazy" can help you out.
注:我是修改2.0为2.2解决问题的

问题2.
The following types may not be used as proxies:
Entitys.login: method get_Upwd should be virtual
Entitys.login: method get_id should be virtual
Entitys.login: method get_Uname should be virtual
Entitys.login: method set_Uname should be virtual
Entitys.login: method get_LastTime should be virtual
Entitys.login: method set_Upwd should be virtual
Entitys.login: method set_id should be virtual
Entitys.login: method set_LastTime should be virtual

----------------------------------------------------------------------------

引起问题的原因:

NHibernate 1.2 默认为类启用了延迟加载功能

解决方法:

方法1.在映射文件 class 标签中添加 Lazy="false" 属性

例:<class name="Entitys.login, Entitys" table="login" lazy="false">

方法2.为每个实体类的属性成员 添加 “ virtual ” 修饰符;

例:   

      public virtual  int id
      {
         get {  return m_id; }
         set {  m_id = value; }
      }
注:我是在映射文件 class 标签中添加 Lazy="false" 属性解决问题的


问题3。
The dialect was not set. Set the property hibernate.dialect
注:在配置文件里设定Nhibernate的方言即可,如NHibernate.Dialect.OracleDialect,NHibernate.Dialect.MsSql2000Dialect
-----------搞定
问题4.
映射的时候,class name值的问题
class name=“命名空间.类名,项目名”
即class name=“NameSpace.类名,ProjectName”
posted @ 2008-08-14 09:36  —无 名  阅读(1013)  评论(2编辑  收藏  举报