I want to map a component with subtypes. The DTD seems not to support a <subclass> tag nested within <component>. Am I missing something? Is this just not supported? Is there a workaround?
Or am I stuck with writing a user type?
________________________________________________
In case you need more detail, here's my situation, boiled down and made humorous:
Code:
class Critter {
BreathingStrategy getBreathingStrategy();
...
}
interface BreathingStrategy {
void breathe();
}
class Lungs implements BreathingStrategy {
Set<Alveolus> getAlveoli();
...
}
class Gills implements BreathingStrategy {
List<Gill> getGills();
...
}
CRITTER:
BREATHING_STRATEGY
...
ALVEOLI:
CRITTER_ID
...
GILL:
CRITTER_ID
...
I'd want to map this roughly as follows:
Code:
<class name="Critter">
<component name="breathingStrategy" class="BreathingStrategy">
<discriminator column="BREATHING_STRATEGY" type="integer" />
<subclass name="Lungs" discriminator-value="0" >
<set name="alveoli">
<key column="CRITTER_ID" />
<one-to-many class="Alveolus" />
</set>
</subclass>
<subclass name="Gills" discriminator-value="1" >
<set name="alveoli">
<key column="CRITTER_ID" />
<one-to-many class="Gill" />
</set>
</subclass>
</component>
</class>
For the sake of this example, the different breathing strategies aren't supposed to know about each other, and the implementation Critter should be completely decoupled from all BreathingStrategy implementations. So I can't cheat by putting both Lungs and Gills on Critter internally, and then just exposing one or the other.
Thoughts?