In case anyone out there is trying to do the same thing I was, I got this to work using external entities in an XML mapping file. This was suggested in the post at
viewtopic.php?f=1&t=930154.
I wrote an XML fragment declaring the common properties in a file called AbstractChoice.hbm.xml. It looks like this:
Code:
<id column="CID" name="cid">
<generator class="native"></generator>
</id>
<property name="choiceNumber"/>
<property name="value" column="ChoiceValue"></property>
<property name="choiceText"/>
<property name="shortText"/>
...
Then, in the two XML files describing the two classes have the properties above in common, I have the following DOCTYPE declaration:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
[ <!ENTITY common SYSTEM "AbstractChoice.hbm.xml"> ]
>
and then a reference to the external entity
common as part of the class element:
Code:
<class name="Choice" table="SurveyChoices">
&common;
<many-to-one name="survey" column="SurveyID" class="Survey"/>
</class>
Note that the "survey" column is only appropriate for Choice and not the other class that uses the common schema, which is why it is here, rather than in AbstractChoice.hbm.xml.
The hibernate.cfg.xml file referenes only Choice.hbm.xml and ChoiceGroupItem.hbm.xml, not AbstractChoice.hbm.xml.
Finally, there is an abstract Java class named AbstractChoice containing the common properties, and then subclasses that extend AbstractChoice for Choice and ChoiceGroupItem.
I'd still like to do this using annotations, so if anyone has any ideas on how to do that I'd love to hear them.