Reputation: 675
Hi guys: Im just studying about HQL
Could anyone explain or provide some links about different between WITH and WHERE in HQL?
fromhttp://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html
example like:
from Cat as cat left join cat.kittens as kitten with kitten.bodyWeight > 10.0
Can I replace with with where ?
thx
Upvotes: 2
Views: 1800
Reputation: 339
Replacing "with" with "where" restricts the result to Cats that have kittens with bodyWeight > 10.0. Using "with" gets even Cats with no kittens.
Upvotes: 1
Reputation: 64638
With
is used to "supply extra join conditions", which means that it is added to the join and not to the where clause:
from Cat as cat
left join cat.kittens as kitten
with kitten.bodyWeight > 10.0
will be translated to something like this;
from Cat as cat
left outer join Cat as kitten
on cat.id = kitten.mother_id
and kitten.bodyWeight > 10.0
while this
from Cat as cat
left join cat.kittens as kitten
where kitten.bodyWeight > 10.0
is translated to
from Cat as cat
left outer join Cat as kitten
on cat.id = kitten.mother_id
where
kitten.bodyWeight > 10.0
Upvotes: 3