2008-05-23

Hibernate - Fetching associations

关键字: hibernate

刚又去看了看Hibernate in action,fetching associations

In HQL, you can specify that an association should be eagerly fetched by an
outer join using the fetch keyword in the from clause:

from Item item
left join fetch item.bids
where item.description like '%gc%'
 


This query returns all items with a description that contains the string gc, and all
their bids, in a single select. When executed, it returns a list of Item instances, with
their bids collections fully initialized. We call this a from clause fetch join. The purpose
of a fetch join is performance optimization: We use this syntax only because
we want eager initialization of the bids collections in a single SQL select

 

 

■ HQL always ignores the mapping document eager fetch (outer join) setting. If
you’ve mapped some associations to be fetched by outer join (by setting
outer-join="true" on the association mapping), any HQL query will ignore
this preference. You must use an explicit fetch join if you want eager fetching
in HQL.

 

原来在映射文件里设置了outer-join="ture",如果在HQL不用fetch的话,一样不会initialized.

希望大家也注意一下:)

BTW:join fetch很好用,前面不知道,每次在jsp因为没有initialized关闭了session而头痛:)

友财网作者 http://www.ucai8.com 友财网

评论
发表评论

您还没有登录,请登录后发表评论

j_butterfly
  • 浏览: 9286 次
  • 性别: Icon_minigender_1
  • 来自: 乌鲁木齐
  • 详细资料
搜索本博客
博客分类
最近加入圈子
存档
最新评论