NHibernateでのサブクラスマッピング継承のテーブルを使用しています。私は親テーブルAttribute
と子テーブルAccountAttribute
を持っています。子AccountAttribute
テーブルにはCustomerProfile
テーブルに別の外部キーがあります。 CustomerProfile
テーブルには、AccountAttribute
テーブルとの関係が0以上あります。私のCustomerProfile
クラスにAccountAttributes
のコレクションがあることを意味します。 CustomerProfile
クラスは、それはAccountAttributes
正しいだと水和されるようにNHibernateのクラスごとの階層テーブルのサブクラスへの結合
は、どのように私はNHibernateのマッピングにAccountAttribute
テーブルにCustomerProfile
テーブルをマッピングしていますか?
表
属性: ATTRIBUTE_ID(PK)
AccountAttribute: AccountAttribute_Id(PK)。 Attribute_Id(FK); CustomerProfile_Id(FK)
CustomerProfile: CustomerProfile_Id(PK)属性/ AccountAttribute階層の
マッピング。 Accountオブジェクトのための
<?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>
マッピング
<?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>
おかげで、
カイル
プライマリキーが1つだけである必要があることに同意します。残念ながら、ここで私に対抗するいくつかのことがあります。 #1 AccountAttributeテーブルには更新可能なフィールドがあるため、主キーが必要です。 #2これは、動的に属性を追加する方法であるため、CustomerProfileとAccountAttributeの関係は必須です(つまり、市、州、郵便番号など)をCustomerProfileに追加することができます。私はそれについてもっと考えるほど、私は継承がこのマッピングにアプローチする正しい方法ではないと思います。 –