在Hibernate中映射多级继承 [英] Mapping multi-Level inheritance in Hibernate
本文介绍了在Hibernate中映射多级继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我有这样的结构:
A
|
+ - B
|
+ - C
它使用连接表映射到每个子类的一个表。由于历史原因,我也使用鉴别器,所以目前情况如 Hibernate手册第9.1.3节。
问题:扩展这样一个结构的映射:
A
|
+ - B
| |
| D
|
+ - C
我可以< subclass>
a < subclass>
在hibernate映射中?
<休眠映射>
< class name =Atable =A>
< id name =idtype =longcolumn =a_id>
< generator class =native/>
< / id>
< discriminator column =discriminator_coltype =string/>
< property name =type =/>
<! - ... - >
< / class>
< subclass name =Bextends =Adiscriminator-value =B>
<! - ... - >
< / subclass>
< subclass name =Dextends =Bdiscriminator-value =D>
<! - ... - >
< / subclass>
< subclass name =Cextends =Adiscriminator-value =C>
<! - ... - >
< / subclass>
< / hibernate-mapping>
Currently I have a structure like this:
A
|
+--B
|
+--C
It's mapped with one table per subclass using joined tables. For historic reasons I also use a discriminator, so the current situation is as described in Section 9.1.3 of the Hibernate manual.
Question: How do I extend the mapping for a structure like this:
A
|
+--B
| |
| D
|
+--C
Can I <subclass>
a <subclass>
in the hibernate mapping? What <key>
s do I need?
解决方案
not tested but, according to the link you posted if you are using hibernate3
<hibernate-mapping>
<class name="A" table="A">
<id name="id" type="long" column="a_id">
<generator class="native"/>
</id>
<discriminator column="discriminator_col" type="string"/>
<property name="" type=""/>
<!-- ... -->
</class>
<subclass name="B" extends="A" discriminator-value="B">
<!-- ... -->
</subclass>
<subclass name="D" extends="B" discriminator-value="D">
<!-- ... -->
</subclass>
<subclass name="C" extends="A" discriminator-value="C">
<!-- ... -->
</subclass>
</hibernate-mapping>
这篇关于在Hibernate中映射多级继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文