-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: HQL with discriminator does not map to any class.
PostPosted: Thu Aug 17, 2006 1:14 pm 
Newbie

Joined: Thu Aug 17, 2006 12:52 pm
Posts: 2
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>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 1:48 am 
Regular
Regular

Joined: Fri Aug 18, 2006 2:40 pm
Posts: 51
Location: Metz, France
HQL 2 returns Object[][] because you used attributes in the select part.

http://www.hibernate.org/hib_docs/v3/re ... hql-select

...
Queries may return multiple objects and/or properties as an array of type Object[]
...

Code:
select new ForumQuestionOverview(doc.versionId, doc.documentId, doc.name)
from ForumQuestion as doc

_________________
Denis
Don't forget to rate ... thanks.


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon Aug 21, 2006 9:56 am 
Newbie

Joined: Thu Aug 17, 2006 12:52 pm
Posts: 2
Thanks, I'll give that a try.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.