Hello... i have a problem on how to map the following simple example scenario.
The Hibernate Reference tells me to use the <subclass>-Tag to map implementig classes of interfaces. But I also need the <subclass>-Tag to express the polymorphic structure, that is i. e. "Question" is extended by "NumericQuestion"
Is the following mapping correct?
Code:
<hibernate mapping>
<class name="Question" table="QUESTIONS" discriminator-value="Question">
<id name="Id" column="ID">
<generator class="native" />
</id>
<property name="questionText" column="QUESTION_TEXT" />
<discriminator column="CLASS_NAME" />
<!-- Now the implementing class -->
<subclass name="QuestionDTO" discriminator-value="QuestionDTO" />
<!-- Now the subinterface -->
<subclass name="NumericQuestion" discriminator-value="NumericQuestion">
<property name="minValue" column="MIN_VALUE" />
<property name="maxValue" column="MAX_VALUE" />
<!-- Now the implementig class of this interface -->
<subclass name="NumericQuestionDTO" discriminator-value="NumericQuestionDTO" />
</subclass>
</class>
</hibernate-mapping>
I am concerned about the lines of code in which the DTOs (stands for "Data Transfer Object") are mapped. It's just one line, where I say what's the name of the implementing class and what discriminator-value I give to it. Is that enough?
I know that later in the running application, its the DTO-Objects, that will be persisted to the database, because you can't create an object of an interface, right? But I'd like the type of the DTOs to be the corresponding interface-type, because one should only access theses DTOs through their interfaces.
How does Hibernate understand, that in one case the <subclass>-Tag is used to declare an implementing class and in another case to declare a real subclass (subinterface in this case)?
For all help best thanks in advance!
Philipp Hinnah