xyz
xyz

Reputation: 2160

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. Why this is happening? Have I done anything wrong?

Upvotes: 0

Views: 88

Answers (1)

singhakash
singhakash

Reputation: 7919

LAZY in JPA (unlike EAGER) is merely a hint, which JPA implementations may ignore.

ObjectDB always loads basic fields eagerly, regardless of the LAZY / EAGER setting.

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.

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

Upvotes: 1

Related Questions