-->
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.  [ 1 post ] 
Author Message
 Post subject: Aggregate functions fail if querying super class
PostPosted: Mon Apr 05, 2004 6:54 am 
Newbie

Joined: Thu Feb 26, 2004 12:27 pm
Posts: 4
Hello,

I am using joined-subclasses and want to use the count function on the super class to get the number of elements which are of the super class (but not of one of the subclasses).


The mapping:
Code:
<class name="News" table="news">
      <cache usage="nonstrict-read-write" />
      <id name="id" column="id" type="long">
         <generator class="identity"/>
      </id>
      <property name="name" />

      <joined-subclass name="GameNews" table="game_news">
         <key column="news" />
         <many-to-one name="game" />
      </joined-subclass>
      <joined-subclass name="GameNews2" table="game_news2">
         <key column="news" />
         <many-to-one name="game" />
      </joined-subclass>
   </class>


The HQL query:
Code:
select count(*) my.package.News as this where this.class = my.package.News


The non-running SQL query:
Code:
select count(*) as x0_0_ from news news0_ where (case when news0__1_.news is not null then 1 when news0__2_.news is not null then 2 when news0_.id is not null then 0 end=0 )

Hibernate seems to generate wrong SQL: The query tries to access properties of the subclass-tables without generating a join.

It does work properly when querying objects:
HQL:
Code:
from my.package.News as this where this.class = my.package.News

running SQL:
Code:
select news0_.id as id, case when news0__1_.news is not null then 1 when news0__2_.news is not null then 2 when news0_.id is not null then 0 end as clazz_, news0__1_.game as game30_, news0__2_.game as game31_ from news news0_ left outer join game_news news0__1_ on news0_.id=news0__1_.news left outer join game_news2 news0__2_ on news0_.id=news0__2_.news where (case when news0__1_.news is not null then 1 when news0__2_.news is not null then 2 when news0_.id is not null then 0 end=0 )


Any help appreciated.

Thanks,
Till

Hibernate 2.1.1
MySQL 4.0.12


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

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.