-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate HQL left join and additional ON clause conditions
PostPosted: Wed Aug 24, 2005 11:30 am 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
Hello,

i have a question, how do i get the following statement done with HQL:

SELECT ..... FROM Company company
LEFT JOIN loginUsers l ON company.loginUserID = l.loginUserID AND l.loginUserActive=1 OR l.loginUserID=12

the "ON" statement is my problem, where i could have OR / AND or NOT connected statements.

Hibernate creates its standard ON statement (i guess) which is something like

LEFT JOIN loginUsers l ON company.loginUserID = l.loginUserID

with no additional conditions....

How to ?


Greetings


tvh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 11:50 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
http://www.hibernate.org/hib_docs/refer ... ryhql.html


Top
 Profile  
 
 Post subject: this doesnt help :-(
PostPosted: Wed Aug 24, 2005 3:27 pm 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
kochcp wrote:
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html


doesnt help because it doesnt cover any joins with multiple conditions in the ON statement !!!


Top
 Profile  
 
 Post subject: Re: Hibernate HQL left join and additional ON clause conditi
PostPosted: Wed Aug 24, 2005 4:25 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
The way I see it, the l.loginUserActive=1 OR l.loginUserID = 12 should just be in the where clause. It's not part of the JOIN.
Code:
SELECT ..... FROM Company company
LEFT JOIN loginUsers l ON company.loginUserID = l.loginUserID
WHERE l.loginUserActive=1 OR l.loginUserID=12


What you're stating sounds like you want to retrieve the loginUsers data if the l.loginUserActive=1 OR l.loginUserID=12 is matched even if there's not a company match.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: Hibernate HQL left join and additional ON clause conditi
PostPosted: Wed Aug 24, 2005 6:22 pm 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
pksiv wrote:
The way I see it, the l.loginUserActive=1 OR l.loginUserID = 12 should just be in the where clause. It's not part of the JOIN.
Code:
SELECT ..... FROM Company company
LEFT JOIN loginUsers l ON company.loginUserID = l.loginUserID
WHERE l.loginUserActive=1 OR l.loginUserID=12


What you're stating sounds like you want to retrieve the loginUsers data if the l.loginUserActive=1 OR l.loginUserID=12 is matched even if there's not a company match.


hi there, thank you for the fast reply ! with my example i try to demonstrate what i want... additional conditions in the joins' ON statement and additionally to that a WHERE statement... the WHERE statement should not contain the conditions which are placed in the ON statement.

Sincerely

tvh


Top
 Profile  
 
 Post subject: Re: Hibernate HQL left join and additional ON clause conditi
PostPosted: Wed Aug 24, 2005 6:32 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
I realize that but do you get any added benefit to joining on fields that aren't part of the key linking the two tables together ? If not, there's no need for the additional ON statements. just use the where clause.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: Hibernate HQL left join and additional ON clause conditi
PostPosted: Thu Aug 25, 2005 3:28 am 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
pksiv wrote:
I realize that but do you get any added benefit to joining on fields that aren't part of the key linking the two tables together ? If not, there's no need for the additional ON statements. just use the where clause.

hi there, thank you for your ideas... below is the statement i try to get into hql to work without using the createSQLQuery statement workaround:

SELECT Companies.companyID, Companies.companyParentID, Companies.companyName, 1 AS userCompanyID
FROM Companies
LEFT OUTER JOIN HiddenUserCompanies HiddenUserCompanies ON Companies.companyID = HiddenUserCompanies.companyID AND HiddenUserCompanies.loginUserID = 94
WHERE (Companies.companyParentID=2) AND (HiddenUserCompanies.userCompanyID IS NULL)
ORDER BY Companies.companyName

"Companies" is a table containing companies in a tree-format, "HiddenUserCompanies" is a table containing companies specific users may not be able to view in the tree....

the left join gives me "null"-column values for "userCompanyID" for users having rights to view the tree....

as you stated, i have to probably rewrite my SQL statement to make it HQL compatible... but i dont think that its going to be solved to move the additional condition "AND HiddenUserCompanies.loginUserID = 94
" into the where clause....

sincerely


tvh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 4:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use HB 3.1beta2 and the HQL "WITH" clause.


Top
 Profile  
 
 Post subject: HQL "WITH" clause ?
PostPosted: Thu Aug 25, 2005 5:12 am 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
gavin wrote:
Use HB 3.1beta2 and the HQL "WITH" clause.

Hi there,

is the HQL "WITH" clause a brand brand new feature of hibernate 3.1 beta 2 ? is there already an api-documentation ?

tahnx for your suggestion so far...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 7:58 am 
Newbie

Joined: Tue Aug 30, 2005 8:14 am
Posts: 5
tvh....did you get the solution for your problem b'coz even I am facing the same problem.


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