-->
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 left join not working
PostPosted: Thu Aug 27, 2009 2:13 pm 
Newbie

Joined: Thu Aug 27, 2009 1:54 pm
Posts: 2
hello, I am a newbie here and would like your opinion on how i can fix this issue i am facing...

I have 3 tables (tabel1, table2, table3) mapped to 3 classes (class1, class2 and class3) using annotations, with the following relationships, say.

Class1 - Class2 (m:n)
Class2 - Class3 (1:m)
Class1 - Class3 (1:m)

I am trying to write a HQL that will load all objects from Class2 and Class3 that belong to a Class1 with the following HQL:

select c2 from Class1 as c1 join c1.class2s as c2 left join c2.class3s as c3 where c3.class1.id=c1.id

The problem here is the result only returns Class2 objects IF they have a Class3 object associated with them (the left join should return ALL Class2 objects irrespective of whether there are Class3 objects associated with them or not...shouldnt it?), the left join does not seem to have any effect on the query!

eg: if a Class1 object has an associated Class2 object, but no associated Class3 object, it should still come up in the result, but it is not doing so.


Top
 Profile  
 
 Post subject: Re: HQL left join not working
PostPosted: Thu Aug 27, 2009 3:12 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Why not just load Class 1 and call the getters for Class2 and Class3? Why do you need HQL?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: HQL left join not working
PostPosted: Thu Aug 27, 2009 4:23 pm 
Newbie

Joined: Thu Aug 27, 2009 1:54 pm
Posts: 2
my design was forced in a way that the 1:m between Classes 1 and 3 was not enforced completely. Class3 has the mapping to Class1 but Class1 does not have a direct mapping to Class3.

I figured there would be issues with HQL only being able to load completely mapped classes and not fetch based on selective conditions like i had in my HQL.

Guess the only option is to enforce the mapping on both sides - and i agree its the best way to do it :) thanks a lot!


Top
 Profile  
 
 Post subject: Re: HQL left join not working
PostPosted: Thu Aug 27, 2009 6:18 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, you kinda solved that yourself. But our pleasure! :)

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.