日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

關(guān)于NHibernate異常The following types may not be ...

 coding 2010-09-11
關(guān)于NHibernate異常The following types may not be used as proxies
2009-08-14 17:56
異常:

The following types may not be used as proxies:
NHibernateDemo.DataAccess.DomainObjects.Customer: method get_Name should be virtual
NHibernateDemo.DataAccess.DomainObjects.PurchaseItem: method set_Id should be virtual.....

需要改的有兩點(diǎn):
例如:Customer.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="
urn:nhibernate-mapping-2.2">
<class name="NHibernateDemo.DataAccess.DomainObjects.Customer, NHibernateDemo.DataAccess" table="Customer"
lazy="false">
<id name="Id" type="Int32" unsaved-value="null">
<column name="ID" length="4" sql-type="int" not-null="true" unique="true" />
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="30" sql-type="nvarchar" not-null="true"/>
</property>
<bag name="CustomerPurchases" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="CustomerID"/>
<one-to-many class="NHibernateDemo.DataAccess.DomainObjects.Purchase, NHibernateDemo.DataAccess"/>
</bag>
</class>
</hibernate-mapping>

1.未能找到元素“urn:nhibernate-mapping-2.0:hibernate-mapping”的架構(gòu)信息
原來(lái)的urn:nhibernate-mapping-2.0改為urn:nhibernate-mapping-2.2

2
.在class中添加lazy=false.

在網(wǎng)上查的資料有三種解決方案,下面轉(zhuǎn)載
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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多