I'm using hibernate v3 and have found a certain aspect of the created tables for subclasses declarations confusing. My mapping is as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
<class name="test.Component" table="component" >
<id name="id" access="field">
<generator class="native"/>
</id>
<discriminator column="type"/>
<subclass name="test.Form" discriminator-value="form" lazy="false">
<join table="form">
<key column="id"/>
<property name="description" />
<many-to-one name="pe" access="field"
column="peid"
not-null="true"
/>
</join>
</subclass>
<subclass name="test.TextField" discriminator-value="textfield" lazy="false"/>
</class>
<class name="test.PE" table="pe">
<id name="id" access="field">
<generator class="native"/>
</id>
<bag name="forms" access="field" cascade="all" inverse="true" lazy="false">
<key column="peid"/>
<one-to-many class="test.Form"/>
</bag>
</class>
</hibernate-mapping>
This mapping creates both a component table and form table as I would suspect but also creates duplicate 'peid' columns, one in form and the other in component. Event though code which uses this mapping appears to load and save correctly, shouldn't the column only be created in the form table? Is this just a side-affect of creating this kind of mapping? If so, is it documented someplace?