Hi all,
I'm trying to run polymorphism with Hibernate and it doesn't run. I've two tables: QUESTION (with id, name and question_type_id) and QUESTION_TYPE (with id and name).
Question has a foerign key to QUESTION. For one QUESTION_TYPE. named "Multivaluated", I want to define a MultivaluatedQuestion class which includes a set of other objects of class Possibilities.
I'm defining the polymorphism in this way:
Code:
<class name="...Question" table="QUESTION" schema="CPOL" discriminator-value="0">
<id...>
<discriminator type="integer" >
<formula>
<!-- CASE WHEN (SELECT type.NAME FROM QUESTION q,QUESTION_TYPE type WHERE q.QUESTION_TYPE_ID = type.ID) IN ('Multivaluated') THEN 1 ELSE 0 END -->
1
</formula>
</discriminator>
<subclass name="...MultiValuatedQuestion" discriminator-value="1">
<set name="posibilities" inverse="true">
<key>
<column name="QUESTION_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="...Posibility" />
</set>
</subclass>
...
When trying to load a Question with a Question_type with name 'Multivaluated' I'm always getting instances of Question in spite of MultivaluatedQuestion. Even with a simple formula that forces to be Multivaluated it returns instances of Question.
What am I doing wrong?
Thanks in advance.