Hibernate XML Mapping: Lazy False or Fetch Select?

蹲街弑〆低调 提交于 2019-11-30 06:05:32
octav

I think Fetch Mode and time of fetch are concepts that don't totally overlap.

Lazy="true|false" controls whether an association is loaded eagerly or on demand.

fetch="select|subselect|join|batch" controls how is that entity or collection loaded, when it's required to be loaded.

So, to answer your question, having fetch="select" means:

"a second SELECT is used to retrieve the associated entity or collection. Unless you explicitly disable lazy fetching by specifying lazy="false", this second select will only be executed when you access the association." (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-fetching)

This doesn't mean that lazy loading is disabled! That's controlled by the lazy="true|false" flag. With lazy="true" and fetch="select" Hibernate will lazy load the collection and will load it with a select. If you set lazy="false", the same select will be executed, the difference will be that it will get executed eagerly. Hope this makes sense.

Have a look here as well: http://community.jboss.org/wiki/AShortPrimerOnFetchingStrategies

If you set it to lazy, then the outer map won't select the employee if it is not necessary. The fetch shows how would it query the employee if it necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!