-->
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: Adding conditions to the "ON" part of an outer joi
PostPosted: Mon Mar 14, 2005 6:36 pm 
Beginner
Beginner

Joined: Mon Mar 14, 2005 6:07 pm
Posts: 36
I am trying (unsuccessfully) to convince Hibernate to produce a query with an extra condition added to the "ON" part of the outer join instead of the "WHERE" clause, like this:

SELECT
p.id, count(c.id)
FROM
parent p
left outer join child c ON c.pid=p.id and c.code='y'
GROUP BY p.id

I've tried changing my HQL and adding a "where" attribute to my mapping, but I always get this SQL generated:

SELECT
p.id, count(c.id)
FROM
parent p
left outer join child c ON c.pid=p.id
WHERE
c.code='y'
GROUP BY p.id

The difference is that the second statement does not return some of the rows that I need. Here is my test data (oversimplified to fit this page :-)

create table parent (id integer);
create table child (id integer,pid integer,code char(1));
insert into parent (id) values (1);
insert into parent (id) values (2);
insert into child (id,pid,code) values (1,1,'n');
insert into child (id,pid,code) values (6,2,'y');
insert into child (id,pid,code) values (7,2,'n');

The query I can generate returns
(2,1);
The query I need would return
(1,0)
(2,1).

Does anyone know a trick I can use to push my condition into the ON clause? Should I post a feature request to JIRA instead?

Thanks in advance,

Sergey


Hibernate version: 2
Name and version of the database you are using: MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 3:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Filters are the only way to get snippets added to the ON clause, and filters are only available in Hibernate3.


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.