-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL outer join + where problem
PostPosted: Mon May 14, 2012 10:36 am 
Newbie

Joined: Thu Mar 12, 2009 2:49 pm
Posts: 9
Location: Vienna
Hi! I got this problem:

This statement returns me (just as I want) 1:
Code:
SELECT Count(distinct obj.id) from class1 obj LEFT OUTER JOIN obj.someCollection str WHERE Per_ID = 15237 OR 0=1


However, the Thing I really would like to know is this:
Code:
SELECT Count(distinct obj.id) from class1 obj LEFT OUTER JOIN obj.someCollection str WHERE Per_ID = 15237 OR str.relation1.relation2.id = 123


But this one gives me a count of zero when the joined collection is empty. If I look at the resulting SQL-statement I can see that the problem is that this "str.relation1.relation2" is translated into a cross join and the connection is done through an added AND-block in the WHERE-clause

How can I achieve the desired result?


Top
 Profile  
 
 Post subject: Re: HQL outer join + where problem
PostPosted: Mon May 14, 2012 10:46 am 
Beginner
Beginner

Joined: Sat Nov 19, 2005 11:54 am
Posts: 22
str.relation1.relation2.id means INNER JOIN
can you send your mapping?
i don`t know relation of your classes to help you


Top
 Profile  
 
 Post subject: Re: HQL outer join + where problem
PostPosted: Mon May 14, 2012 11:06 am 
Newbie

Joined: Thu Mar 12, 2009 2:49 pm
Posts: 9
Location: Vienna
thanks for the answer. well its quite a complicated class web, so if this stepping through the properties means inner join, should I try using outer joins for each of those properties along the way instead of this simple a.b.c snytax? or is there an easier way then one outer join block for each step?


Top
 Profile  
 
 Post subject: Re: HQL outer join + where problem
PostPosted: Mon May 14, 2012 11:22 am 
Newbie

Joined: Thu Mar 12, 2009 2:49 pm
Posts: 9
Location: Vienna
Okey, so that was the hint I needed, that way it works. So instead of
Code:
SELECT Count(distinct obj.id) from class1 obj LEFT OUTER JOIN obj.someCollection str WHERE Per_ID = 15237 OR str.relation1.relation2.id = 123


I now use
Code:
SELECT Count(distinct obj.id) from class1 obj LEFT OUTER JOIN obj.someCollection a LEFT OUTER JOIN a.relation1 b LEFT OUTER JOIN b.relation2 c WHERE Per_ID = 15237 OR c.id = 123


Not as beautiful as the first one, but has the advantage that it does what I want ;)


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