开发者

fetch="join" and hql

开发者 https://www.devze.com 2023-02-16 12:00 出处:网络
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\" />

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消