-->
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: Help needed with a HQL query using multiple tables
PostPosted: Fri Jul 22, 2011 9:19 am 
Newbie

Joined: Thu Jul 21, 2011 4:57 pm
Posts: 3
I am needing help trying to translate an SQL query to a working HQL query. My statement is as follows:

SELECT service
FROM Service service
INNER JOIN ServiceUser srvUsr
ON service.serviceId = srvUsr.service.serviceId
JOIN User user
ON srvUsr.user.userId = user.userId
WHERE user.company = :company
ORDER BY user.lastName ASC;

Basically, I am needing to get back all service objects sorted by the last name of the user objects that each service object has. Because there is no direct relationship between the service object and the user object, I have to do a three table join in order to reach the last name property and be able to sort on it so that the service objects are in the correct order. The error that I am getting from Hibernate is that it does not like the INNER JOIN...ON clause. I read that this is a bug that has not been addressed and it was suggested that I just use a natural join, which I did. Then I got an error on the second JOIN...ON clause because of the 'ON' keyword. I tried to remove that but to no avail. The error I got from there is that the JOIN statement is expecting a statement to join on. Any help would be appreciated. Thanks!!


Top
 Profile  
 
 Post subject: Re: Help needed with a HQL query using multiple tables
PostPosted: Fri Jul 22, 2011 3:23 pm 
Newbie

Joined: Thu Jul 21, 2011 4:57 pm
Posts: 3
Nevermind...issue has been solved. FYI, here is the resolution:

SELECT service
FROM Service service
INNER JOIN service.serviceUsers srvUser
JOIN srvUser.user user
WHERE service.company = :company
ORDER BY user.lastName ASC;

Didn't realize that I needed to use the drilled down object for the joins instead of an arbitrary object of that same type.

Oh well, you live and learn...


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.