考虑下面的映射文件。这两个类对于businessId是什么有不同的概念,由对象模型处理,但可以将其存储为一列中的普通字符串。我还希望它们与分配集具有相同的关系,这是我希望使用继承映射它们的主要原因。
虽然今天项目的业务id与帐户相同的可能性很小,但如果有一种方法可以使businessId和鉴别器的组合都成为自然id的一部分,那将是最理想的。这是不允许的,也许是因为一些我看不到的好理由。
我能以某种显而易见的方式改进这个映射吗?
干杯,
Berryl
<class name="ActivitySubject" table="ActivitySubjects" discriminator-value="BASE_CLASS">
<id name="Id" unsaved-value="0">
<column name="ActivitySubjectId" />
<generator class="hilo" />
</id>
<discriminator column="ActivitySubjectType" type="System.String" />
<natural-id mutable="true">
<property name="BusinessId" length="25" not-null="true" />
</natural-id>
<property name="Description" length="75" not-null="true" />
<set access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" name="Allocations">
<key foreign-key="Allocations_Resource_FK">
<column name="ActivityId" />
</key>
<one-to-many class="Allocation />
</set>
<subclass name="Account" discriminator-value="ACCOUNT" />
<subclass name="SProject" discriminator-value="PROJECT" />
下面是我最终让这两个列成为同一唯一索引的一部分的方法:
<discriminator type="System.String" >
<column name="ActivitySubjectType" unique-key="ActivitySubjectTypeBusinessId" />
</discriminator>
<property name="BusinessId" length="25" not-null="true" node="1" unique-key="ActivitySubjectTypeBusinessId"/>发布于 2010-12-24 22:08:16
不要对主键使用自然ids。我将使用合成键、数据库生成的标识或GUID作为主键,并对BusinessId和ActivitySubjectType的组合添加唯一约束。
https://stackoverflow.com/questions/4522068
复制相似问题