fetch="join" and hql
I'm quite confused about the fetch-attribute in a many-to-one mapping (class Order):
<many-to-one name="Product" column="ProductId" lazy="false" fetch="join" />
Now, if I write a hql-query like
from Order where Order.OrderId = x
Isn't Hibernate supposed to generate one SQL-Query, joining the Product? In my case, two queries happen and I'm not sure if the fetch-attribute wi开发者_JAVA百科thin the mapping is ignored for some reason...
HQL does not respect fetch="join"
. You need to do it explicitly:
from Order o
join fetch o.Product
o.OrderId = x
(I might add lazy="false"
is almost always a bad idea, but this will get you going)
精彩评论