Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
If I run HQL 1, I am returned a list of classes of type ForumQuestion, which is what I would expect.
But if I run HQL 2, the query seems to run fine, but I get a class cast exception when I try to cast to a ForumQuestion.
Code:
ForumQuestion f = (ForumQuestion)query.list().get(0)
When I print out
Code:
list.get(0).getClass().getName()
I get java.lang.Object.
It seems as though Hibernate does not use the discriminator value when I list out the column names.
The generated SQL seems to be the same except for the aliases generated.
Any suggestions on how to get this to map correctly would be appreciated.
1. HQL:
Code:
select doc from ForumQuestion as doc
Generated sql:
Code:
SELECT forumquest0_.version_id AS version1_27_,
forumquest0_.document_id AS document3_27_,
forumquest0_.document_name AS document4_27_
FROM document forumquest0_
WHERE forumquest0_.doc_type = 8
2. HQL:
Code:
select doc.versionId, doc.documentId, doc.name from ForumQuestion as doc
Generated sql:
Code:
SELECT forumquest0_.version_id AS col_0_0_,
forumquest0_.document_id AS col_1_0_,
forumquest0_.document_name AS col_2_0_
FROM document forumquest0_
WHERE forumquest0_.doc_type = 8
Code:
<hibernate-mapping package="eg">
<class name="ContentItemVO" table="document" lazy="true" entity-name="ContentItem" discriminator-value="not null">
<id name="versionId" column="version_id">
<generator class="sequence">
<param name="sequence">x_sequence</param>
</generator>
</id>
<discriminator column="doc_type" type="integer"/>
<property name="documentId" column="document_id" "/>
<property name="name" column="document_name"/>
<subclass name="eg.ForumQuestionVO" lazy="true" discriminator-value="8" entity-name="ForumQuestion">
</subclass>
</class>
</hibernate-mapping>