-->
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.  [ 2 posts ] 
Author Message
 Post subject: select cat, count( elements(cat.kittens) ) from eg.Cat cat g
PostPosted: Tue Mar 23, 2004 3:01 pm 
Newbie

Joined: Tue Mar 23, 2004 2:32 pm
Posts: 3
Hi,

Code:
select cat, count( elements(cat.kittens) ) from eg.Cat cat g

This example from documentation returs only cats which have at least one kitten but I need it to return even cats without kittens among the results (eg. count = 0).
Question1: How to accomplish that (and working independently of used DB)?


I have created such HQL:


Code:
select cat, count(kitten.id) from eg.Cat cat left join cat.kittens kitten group by cat

That would be fine, BUT I have a where condition on the retrival of kittens:
<bag name="kittens" where="some condition">...</bag>

This condition is added into WHERE clause of the generated SQL (I'm using MySQL dialect):

Code:
select cat.*, count(kitten.id) from cat left join kittens on (cat.id=kittens.parent_id)
where some condition;


Instead of placing the where condition inside the ON condition where is the appropriate place:
Code:
select cat.*, count(kitten.id) from cat left join kittens on (cat.id=kittens.parent_id and some condition);


Question2: Is this a bug or a feature?


I have even tried to solve this problem using createSQLQuery(), but without success because it is not possible to get the count() - no persistent class for Integer.class.


Any help? Do I have to go below to JDBC connection and lost the independency of DB?

Thanks a lot in advance,
Karel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 7:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is intended functionality, that will change in Hibernate 2.2.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.