Hibernate version: 3.0b4
Following is an excerpt of a mapping document which has the problem
Mapping documents:
Code:
<class name="NetworkObject" abstract="true">
<id name="id"
type="int"
column="ID"
unsaved-value="-1">
<generator class="native"/>
</id>
<discriminator column="OBJ_TYPE" type="string"/>
<version name="version"
type="int"
column="VERSION"/>
<!-- Common name property. -->
<property name="name"
type="string"
column="NAME"
length="100"
update="false"/>
< ... other properties ommited ... >
<!--
define base hierarchy classes.
Note the referenced classes are synthetic classes only used to support
the Hibernate inheritance mechanism which only allows union-subclass to
exist as a child element of class and cannot exist as a child of hibernate-mapping.
Each concrete hierarchy root defines a private version of the 'Base' class to satisfy Hibernate
-->
<union-subclass name="BaseNE" abstract="true" table="NE" />
<union-subclass name="BasePort" abstract="true" table="PORT"/>
table="ROUTE"/>-->
<subclass name="NE" extends="BaseNE">
<....>
</subclass>
<!-- Port Hierarchy (mapped into its own table, specified in BasePort -->
<subclass name="Port" extends="BasePort">
<property name="slot" type="int" column="SHELF_SLOT"/>
<property name="index" type="int" column="PORT_INDEX"/>
<many-to-one name="ne"
class="NE"
column="NE_ID" />
< ... >
</subclass>
<subclass name="ATMPort" extends="Port" discriminator-value="A"/>
<subclass name="GEPort" extends="Port" discriminator-value="G"/>
The intention is to have all classes derived from NetworkObject reside in
several tables, one per sub-hierarchy, whilst still having all the properties
defined in NetworkObject above. Secondly there's a couple of other classes, not mentioned here, which have references to NetworkObject type objects (collections thereof).
This mapping code is compiled/parsed successfully by the SchemaExport
tool and generates a ddl fragment. The problem stems from the fact
that the generated tables do not have a primary key constraint generated
for them and so, generated foreign keys like the NE_ID in the Port subclass above cannot be created since the NE table does not have the ID column (as inherited
from NetworkObject) as primary key.
Can I use this technique at all to achieve what I want?
Looking at the code, Port and NE are both instances of DenormalizedTable
and it seems that it does not use the idValue property of the included
table. Is this a bug?