1
NHibernateを使用してサプライヤドメイン内の "IList"プロパティを設定しようとしているときに "コレクションの読み込みに違法なアクセス"例外が発生します。私はグーグルで得たすべての提案を試してみましたが、何も私はあなたの助け/提案を認める大幅でしょう。ここ:(nhibernate <bag>例外 - ローディングコレクションへの不正アクセス
を助け、私のドメインオブジェクトと.HBMファイルがあるように思わない。
サプライヤードメインオブジェクト
namespace Inventory.DomainObjects
{
[Serializable]
public class Supplier
{
public virtual string SupplierID { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual IList<Address> Address { get; set; }
}
}
アドレスのドメインオブジェクト
namespace Inventory.DomainObjects
{
[Serializable]
public class Address
{
public virtual int AddressID { get; set; }
public virtual string SupplierID { get; set; }
public virtual string Line1 { get; set; }
public virtual string Line2 { get; set; }
public virtual string Line3 { get; set; }
}
}
Supplier.HBM
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Inventory.DomainObjects"
assembly="Inventory">
<class name="Supplier" table="Inv_Supplier">
<id name="SupplierID" column="SupplierId" type="string"/>
<property name="SupplierCode" column="Code" type="string"/>
<property name="Name" column="SupplierName" type="string"/>
<property name="Description" column="SupplierDescription" type="string"/>
<bag name="Address" cascade="all" inverse="true" lazy="true">
<key column="SupplierID" not-null="true"/>
<one-to-many class="Address" not-found="ignore"/>
</bag>
</class>
</hibernate-mapping>
これは疑わしい
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Inventory.DomainObjects"
assembly="Inventory">
<class name="Address" table="Inv_Supplier_Address" lazy="false">
<id name="AddressID" column="AddressId" type="integer"/>
<property name="Line1" column="Line1" type="string"/>
<property name="Line2" column="Line2" type="string"/>
<property name="Line3" column="Line3" type="string"/>
<many-to-one name="SupplierID" column="SupplierId" not-null="true" class="Supplier" />
</class>
</hibernate-mapping>
のイメージ)をNO PRIMARを含む別のテーブル(Inv_Images) Yキーを押すが、SupplierIdを外部キーとして持つサプライヤの複数のイメージが含まれていますか? NO Primary Keyを含むImageテーブルのHBMマッピングファイルを定義することができません。 –
Alex
Supplier
プロパティを参照するために(このようなあなたのHBMマッピングファイルを変更本当にありがとうございましたあなたの提案はうまくいきました。愚かなことに、私はそれに気づいていませんでした:(サプライヤーオブジェクトのリストプロパティ(IList