nhibernate<子类><加入>嵌套另一个子类映射(导致叶类的重复插入)加入>子类>
这个映射有什么问题吗? 保存 Class3 的实例时,将在 Table_2 中插入两行!
第一行将 Column4 设置为 null,并将 Column3 的值设置为正确, 第二行将 Column3 设置为 null,并将 Column4 的值设置为正确!
<class name="Class1" table="Table_1">
<id name="Column1">
<generator class="native" />
</id>
<discriminator column="ColumnDisc" />
<property name="Column2" type="int" />
<subclass name="Class2">
<join table="Table_2">
<key column="Column1" />
<property name="Column3" type="int" />
</join>
<subclass name="Class3" >
<join table="Table_2">
<key column="Column1" />
<property name="Column4" type="int" />
</join>
</subclass>
</subclass>
</class>
What's wrong with this mapping?
On saving an instance of Class3, two rows in Table_2 will be inserted!
first row has Column4 set to null and correct value of Column3,
and second row has Column3 set to null and correct value of Column4!
<class name="Class1" table="Table_1">
<id name="Column1">
<generator class="native" />
</id>
<discriminator column="ColumnDisc" />
<property name="Column2" type="int" />
<subclass name="Class2">
<join table="Table_2">
<key column="Column1" />
<property name="Column3" type="int" />
</join>
<subclass name="Class3" >
<join table="Table_2">
<key column="Column1" />
<property name="Column4" type="int" />
</join>
</subclass>
</subclass>
</class>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在哪里设置每个派生类型的鉴别器值?
如果我相信您在评论中指出的链接,则类映射如下所示:
如果我将您的映射与此映射进行比较,您会发现您的
标记中缺少discriminator-value
属性。确保为要映射的每个子类设置正确的鉴别器值。我建议尝试一下,看看它是否效果更好,或者是否会引发另一个问题。 =)
希望这有帮助! =)
Where do you set the discriminator value for each of the derived types?
If I believe the link to which you pointed in your comment, the class mapping looks like this:
If I compare your mapping with this one, you lack
discriminator-value
attribute within your<subclass>
tag.Make sure you set the right discriminator values for each of the subclasses you intend to map. I suggest trying this and figure out whether it works better, or if this raised another problem. =)
Hope this helps! =)