Hibernate version: 3.1.2
Name and version of the database you are using: Oracle 9i
I have a scenario like this:
There is a number of parent classes which all have a child of same basic abstract type. For each child I have created a subclass that identifies the type and added a discriminator.
In one of the parents I have this one-to-one mapping:
Code:
<one-to-one name="afdeling" cascade="all" property-ref="parent" class="BehandlingstilbudAfdelingPojo"/>
The children are all specializations of one abstract type called Afdeling.
Code:
<class table="AFDELING" discriminator-value="AFDELING" name="AfdelingPojo">
<id name="id">
<generator class="sequence">
<param name="sequence">MY_SEQ</param>
</generator>
</id>
<discriminator column="TYPE"/>
...
</class>
In one of the child subclasses I have:
Code:
<subclass name="BehandlingstilbudAfdelingPojo" discriminator-value="BEHANDLINGSTILBUD">
<many-to-one not-null="false" unique="true" column="BEHANDLINGSTILBUD_ID" foreign-key="BEHANDLINGSTILBUDAFDLING_CONS" cascade="all" name="parent" class="BehandlingstilbudPojo"/>
</subclass>
This works just fine and results in a (child) table schema like this.
----------------------------------------------------------------------------------
| AFDELING |
----------------------------------------------------------------------------------
|ID | TYPE | <columns for each property> | BEHANDLINGSTILBUD_ID
This gives me a link from the child to the parent "BEHANDLINGSTILBUD" which is what I want.
Now, my problem is that I have a design in which there are 11 child-implementations of the abstract child class. Using the approach above this will give me an additional 10 xxxx_ID columns in the AFDELING table. In any given row only one of the 11 xxxx_ID columns will contain an ID, the rest will be null.
Is there a way to collapse all these xxxx_ID columns to parent id's into a single "PARENT_ID" column? I already have the discriminator value column "TYPE" to tell me what type of parent I should join the child to. So I think it should be possible.
I have read everything I could find that the manual had to say about discriminators and their use. I also have the HIA book and has not found an answer in that either.
I have not been able to find what I was looking for, but if you happen to know it is documented somewhere please just point me to the chapter/page and I will be perfectly happy with that solution :)
TIA