NHibernate で継承をマッピングするサブクラスごとのテーブルを使用しています。親Attribute
テーブルと子AccountAttribute
テーブルがあります。子AccountAttribute
テーブルには、テーブルへの別の外部キーがありCustomerProfile
ます。テーブルには、テーブルCustomerProfile
との関係が 0 個以上ありAccountAttribute
ます。AccountAttributes
つまり、CustomerProfile
クラス に のコレクションがあります。
クラスが正しくハイドレートされるように、NHibernate マッピングでCustomerProfile
テーブルをテーブルにマップするにはどうすればよいですか?AccountAttribute
CustomerProfile
AccountAttributes
テーブル
属性: Attribute_Id (PK)
AccountAttribute: AccountAttribute_Id (PK); Attribute_Id (外部キー); CustomerProfile_Id (外部キー)
CustomerProfile: CustomerProfile_Id (PK)
Attribute/AccountAttribute 階層のマッピング。
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Attribute, CustomerProfile" lazy="false">
<id name="Identifier" column="Attribute_Id" access="field.camelcase">
<generator class="identity"/>
</id>
<joined-subclass name="AccountAttribute, CustomerProfile" table="AccountAttribute" lazy="false">
<key column="Attribute_Id" />
<property name="ValueText" column="Value_Txt" access="nosetter.camelcase" />
</joined-subclass>
</class>
</hibernate-mapping>
Account オブジェクトのマッピング
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Account, CustomerProfile" lazy="false">
<id name="Identifier" column="Account_Id" access="field.camelcase">
<generator class="identity"/>
</id>
<!-- How do I map to the AccountAttributes table here to get the correct set? -->
<bag name="AccountAttributes" access="field.camelcase" table="AccountAttribute">
<key column="Account_Id" />
<one-to-many class="AccountAttribute, CustomerProfile"/>
</bag>
</class>
</hibernate-mapping>
ありがとう、
カイル