-->
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.  [ 6 posts ] 
Author Message
 Post subject: [newbie] Self Join in HQL?
PostPosted: Sat Jan 10, 2004 10:13 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
Hi All,

OK I wish to write a bit of HQL to detect, say, all Cats who are more than 2 years apart in age. In SQL thats an easy self join, but as far as I can see in HQL you can't self join unless a pre-existing relationship has been set up in the mappings for the Cat class.

So, how would I write a self join HQL query without such a relationship? Who cares about cats that are more than two years apart in age? I don't like cats.... ;-)

Jay


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 10:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
from Cat older, Cat younger where older.age - younger.age > 2


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 11:17 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
gavin wrote:
Code:
from Cat older, Cat younger where older.age - younger.age > 2


Cool! Thanks Gavin, I tried something like that but must of screwed up the syntax a bit cuz I got an error message

J


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 10:18 am 
Newbie

Joined: Fri Jul 09, 2004 11:49 am
Posts: 1
I ask in this topic because my question is rather similar.

gavin wrote:
Code:
from Cat older, Cat younger where older.age - younger.age > 2


Doing like this i have inner join, and when there is no local translations i get 0 rows.

Code:
"select base, local from Translation base, Translation local
where base.lang = :baseLang
and local.lang = :localLang
and base.entry = local.entry"


i need smth like:

Code:
select base, local from Translation base left outer join Translation local


but I get exception: outer or full join must be followed by path expression

So, how can I implement self left join?
Thanks.


Top
 Profile  
 
 Post subject: Self Outer Join
PostPosted: Sat Mar 11, 2006 4:19 am 
Newbie

Joined: Sat Mar 11, 2006 4:15 am
Posts: 1
Hi
I am facing same problem. How can we implement [b]self outer join[/b] in hibernate.

Please help


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 11, 2006 9:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
In HQL you require the relationship to be mapped for out join. Use native SQL query.


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