要するに:一意制約の1つのフィールドが抽象クラスのマッピングの一部であり、別のフィールドがサブクラスマッピングで定義されている、2列の一意制約を持つ休止状態のxmlマッピングを記述する方法はありますか?
長いバージョン: 私はAbstractCustomFieldValue
他の 2 つのクラス、いくつかのエンティティRefType
と別のエンティティを参照するクラスを持っていますCustomField
。AbstractCustomFieldValue
以下に示すように、いくつかの実装があります。
public abstract class AbstractCustomFieldValue<RefType extends SomeInterface>
{
protected long id;
protected RefType refObjekt;
protected CustomField customField;
protected String value;
}
public class MyEntityCustomFieldValue extends AbstractCustomFieldValue<MyEntity>
{
}
public class MyOtherEntityCustomFieldValue extends AbstractCustomFieldValue<MyOtherEntity>
{
}
AbstractCustomFieldValue
は抽象クラスとしてマップされ、実装はサブクラスとしてマップされます。
<class name="AbstractCustomFieldValue" abstract="true">
<id name="id">
<generator class="MyUniqueIdGenerator"/>
</id>
<many-to-one name="customField" class="CustomField" column="customfield_id"/>
<property name="value" length="65535"/>
</class>
<union-subclass name="MyEntityCustomFieldValue" extends="AbstractCustomFieldValue" table="my_entity_customfield_values">
<many-to-one name="refObjekt" class="MyEntity" column="ref_id"/>
</union-subclass>
<union-subclass name="MyOtherEntityCustomFieldValue" extends="AbstractCustomFieldValue" table="my_other_entity_customfield_values">
<many-to-one name="refObjekt" class="MyOtherEntity" column="ref_id"/>
</union-subclass>
との組み合わせは一意である必要がrefObjekt
あります。customField
このマッピングでこれを達成する方法はありますか?
customField
ハイバネートせずにデータベースに一意のキーを定義するか、抽象マッピングから削除してサブクラス マッピングに配置するオプションがまだあります。
<properties name="myUniqueKey" unique="true">
<many-to-one name="customField" class="CustomField" column="customfield_id"/>
<many-to-one name="refObjekt" class="MyEntity" column="ref_id"/>
</properties>
しかしcustomField
、抽象クラスのマッピングを維持しながら、休止状態の一意の制約を定義できる方法はありますか?