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!!
|