0

I'm probably being dense about this but a query isn't returning the results I'm expecting...

I have two tables(entities): Properties and Landlords as follows:

Properties is made up of the fields (amongst others): Id, propertyRef and landLordsid (which is a many-to-one join to table Landlords).

Landlords is made up of the fields (amongst others): Id, landlordName and the one-to-many Collection for the join.

I want the query to return all the properties for the landlord as passed in via the Integer parameter 'landLord', e.g. if the parameter is 2 then filter for Properties.landLordsid that equals 2. This is the NamedQuery I'm currently using but it returns all properties and doesn't seem to filter.

SELECT p 
from Properties p 
JOIN p.landLordsid l 
WHERE l.id = :landLord

Any ideas what's wrong with the query?

Bohemian
  • 412,405
  • 93
  • 575
  • 722

1 Answers1

0

Let hibernate do the joining for you:

This HQL should work:

from Properties p 
where p.landLord.id = :landLord

Note how the join is implied and that "select *" is also implied.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Thanks for your help Bohemian. It turned out that I was passing an incorrect copy of a Map from a previous query to the application client, hence why the results didn't change!! But at least now I've learnt that a join and a select can be implied. – Russell Martin Feb 11 '13 at 20:47
  • It be a clearer example to write `where p.landLord = :landLord` or `p.landLord.id = :landLordId`. Personally I prefer the former. – carbontax Feb 12 '13 at 13:31