0

NHibernate で継承をマッピングするサブクラスごとのテーブルを使用しています。親Attributeテーブルと子AccountAttributeテーブルがあります。子AccountAttributeテーブルには、テーブルへの別の外部キーがありCustomerProfileます。テーブルには、テーブルCustomerProfileとの関係が 0 個以上ありAccountAttributeます。AccountAttributesつまり、CustomerProfileクラス に のコレクションがあります。

クラスが正しくハイドレートされるように、NHibernate マッピングでCustomerProfileテーブルをテーブルにマップするにはどうすればよいですか?AccountAttributeCustomerProfileAccountAttributes

テーブル

属性: 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>

ありがとう、

カイル

4

1 に答える 1

0

あなたの問題は、サブクラスにテーブル、AccountAttribute_idつまりAccountAttribute.

table-per-subclassを使用していると言ったように、すべてのサブクラス テーブルはスーパークラスの主キーを使用する必要があるため、テーブルはテーブルへの外部キーでもある主キーとしてAccountAttributeのみ持つ必要があります。 Attribute_idAttribute

これらの変更を行うと、正しいマッピングが使用されるため、マッピングが機能するはずです。<key />


参照:

于 2011-01-20T00:18:11.900 に答える