简体   繁体   English

休眠中的懒惰获取

[英]Lazy fetching in hibernate

class A{
    private List<B> bs;
}

class B{
    private String fieldA;
    @Basic(fetch = FetchType.LAZY)
    private String fieldB;
}

when I do : 当我做 :

from A

It also returns fieldB data which I have initialized lazy. 它还返回我已初始化为lazy的fieldB数据。 Why this is happening? 为什么会这样呢? Have I done anything wrong? 我做错了什么吗?

LAZY in JPA (unlike EAGER) is merely a hint, which JPA implementations may ignore. JPA中的LAZY(与EAGER不同)只是一个提示,JPA实现可能会忽略它。

ObjectDB always loads basic fields eagerly, regardless of the LAZY / EAGER setting. 不管LAZY / EAGER设置如何,ObjectDB总是急切地加载基本字段。

If you have very large strings that you want to load lazily - keep them in separate entity objects. 如果您要延迟加载非常大的字符串,请将其保留在单独的实体对象中。 For example, you can define an entity class, LargeString, with a single String field, setting references to LargeString as LAZY. 例如,您可以定义一个带有单个String字段的实体类LargeString,并将对LargeString的引用设置为LAZY。

Alternatively, you can use queries to retrieve only selected fields. 或者,您可以使用查询仅检索选定的字段。 But still keeping the large strings in separate entities may be more efficient, if usually these strings are not required. 但是,如果通常不需要这些大字符串,将大字符串保留在单独的实体中可能会更有效率。

Source1 , Source2 源1 ,源2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM