views:

1233

answers:

3

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?

+3  A: 

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>
shyam
Seems to work. Thank you very much!
Henning
A: 

How would this be done with annotations?

evan.leonard
A: 

See here - the hibernate team says: "impossible" :)

Michal Bachman
that's an answer to the annotation question...
Michal Bachman