Hi
We are using Hibernate 2.x with hbm xml mapping and trying the following:
We have a 3 level inheritance hierarchy and are using table per subclass.
Class C extends Class B, Class B extends Class A.
The table structure is:
Table A has PK_A
Table B has PK_B and a separate column PK_A (which obviously is a foreign key to PK_A in table A)
Table C has PK_C and a separate column PK_B (which obviously is a foreign key to PK_B in table B)
ALL PKs have associated sequences in the database.
Code:
class A
{
pkA;
}
class B extends A
{
pkB;
}
class C extends B
{
pkC;
}
The mapping looks like this:
Code:
<class
name="A"
table="TBL_A"
>
<id
name="pkA"
type="java.lang.Integer"
column="PK_A"
>
<generator class="sequence">
<param name="sequence">A_SEQ</param>
</generator>
</id>
<property...
</class>
<joined-subclass
name="B"
table="TBL_B"
extends="A"
>
<key column name="PK_A" />
<property
name="pkB"
type="java.lang.Integer"
column="PK_B"
not-null="true"
/>
</joined-subclass>
<joined-subclass
name="C"
table="TBL_C"
extends="B"
>
<key column name="PK_B" />
<property
name="pkC"
type="java.lang.Integer"
column="PK_C"
not-null="true"
/>
</joined-subclass>
I have the following questions:
1. is this the right approach ? and whether the mapping is correct.
2. Since "joined-subclass" tag will not support "id" tag like "class" tag does, how do i define the sequences for the separate PKs for the joined subclasses (e.g. PK_B and PK_C above)?
in Joined-subclass parent id down to the child tables. Unfortunately our requirements here demand that every child table have its own id which in turn is used as FK in other tables. This scenario is just part of the "whole" design!
For one I am curious as to how hibernate will handle this issue of a joined-subclass having its own id that is generated through a sequence. or i cant do that at all??
Thx