0
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?

7
  • do you need List of B's when you fetch A ? Commented Mar 19, 2015 at 17:13
  • Lazy fetching works in associations like OneToMany mapping or ManyToMany mapping. So when you fetch A, list of B's is fetched and it will fetch all instance fields in B Commented Mar 19, 2015 at 17:15
  • possible duplicate of JPA fetchType.Lazy is not working Commented Mar 19, 2015 at 17:24
  • @Arkantos yes.thanks . How can I fix this? Commented Mar 19, 2015 at 17:27
  • @singhakash Can you plz tell me how can I detach an in Query?Is not there any other way? Commented Mar 19, 2015 at 17:33

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

After having you Source2 Link ,and scroll down to check the post commented on 2012-02-02 17:36,it says even after modifing the classes you can load the entity.How can we resolve this situation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.