本文介绍了休眠XML映射:懒惰错误或提取选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题。

 <多对一名称=雇员
class我的项目中找到了这个Hibernate配置:

=com.myapp.Employee
cascade =merge
lazy =false
fetch =select>
< column name =employee_id
sql-type =bigint
not-null =true/>
< /多对一>

fetch =select表示延迟加载所有基于的收藏和实体。但是通过写 lazy =false表示不要延迟加载。所以上面的配置说:禁用延迟加载,启用延迟加载。实际上,这意味着该属性被延迟加载?



所以我可以缩短配置为:



<$ p $ <多对一名称=员工
class =com.myapp.Employee
cascade =merge
fetch =select >
< column name =employee_id
sql-type =bigint
not-null =true/>
< /多对一>

但是不是默认模式?所以实际上,我可以声明相同的配置:

 <多对一名称=雇员
class =com.myapp.Employee
cascade =merge>
< column name =employee_id
sql-type =bigint
not-null =true/>
< /多对一>

我是否正确?错误?想法?谢谢

如果我想启用延迟加载,我必须添加 lazy =true并删除 lazy =false

解决方案

我认为抓取模式和抓取时间是不完全重叠的概念。



Lazy =true | false控制关联是否被急切或按需加载。

fetch =select | subselect | join | batch控制该实体或集合在需要加载时如何加载。



所以,要回答你的问题,有 fetch =select表示:

并不意味着懒惰加载被禁用!这是由 lazy =true | false标志控制的。
使用 lazy =true fetch =select Hibernate会延迟加载集合,加载一个选择。如果你设置了 lazy =false,同样的选择将被执行,不同之处在于它会被急切地执行。希望这是有道理的。



看看这里:


I have a simple question. I found this Hibernate config on our project:

<many-to-one name="employee"
    class="com.myapp.Employee"
    cascade="merge"
    lazy="false"
    fetch="select">
<column name="employee_id"
     sql-type="bigint"
     not-null="true"/>
</many-to-one>

Doesn't fetch="select" mean "Lazy load all the collections and entities" based on Fetching Strategies. But by writing lazy="false" mean do not lazy load. So the config above says: "Disable lazy loading. Enable lazy loading." In effect, this means the property is lazy loaded?

So I could shorten that config as:

<many-to-one name="employee"
    class="com.myapp.Employee"
    cascade="merge"
    fetch="select">
<column name="employee_id"
     sql-type="bigint"
     not-null="true"/>
</many-to-one>

But isn't fetch="select" the default mode? So in effect, I can declare the same config as:

<many-to-one name="employee"
    class="com.myapp.Employee"
    cascade="merge">
<column name="employee_id"
     sql-type="bigint"
     not-null="true"/>
</many-to-one>

Am I correct? Wrong? Ideas? Thanks

If I want to enable lazy loading, I must add lazy="true" and remove lazy="false"?

解决方案

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:

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

这篇关于休眠XML映射:懒惰错误或提取选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:17