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?

Rob
  • 6,247
  • 2
  • 25
  • 33
xyz
  • 2,160
  • 3
  • 20
  • 31
  • do you need List of B's when you fetch A ? – Arkantos Mar 19 '15 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 – Arkantos Mar 19 '15 at 17:15
  • possible duplicate of [JPA fetchType.Lazy is not working](http://stackoverflow.com/questions/18693849/jpa-fetchtype-lazy-is-not-working) – singhakash Mar 19 '15 at 17:24
  • @Arkantos yes.thanks . How can I fix this? – xyz Mar 19 '15 at 17:27
  • @singhakash Can you plz tell me how can I detach an in Query?Is not there any other way? – xyz Mar 19 '15 at 17:33
  • Ok when you fetch A, you still need list of B's but not all fields in B, you need to ignore one field (fieldB) and lazy fetch it later.. is that correct ? If it's just one field mapped to some column, why not just ignore it ? – Arkantos Mar 19 '15 at 17:37
  • @Arkantos that field contains large string data..so cant ignore it! – xyz Mar 19 '15 at 18:17

1 Answers1

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

singhakash
  • 7,891
  • 6
  • 31
  • 65
  • 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? – xyz Mar 19 '15 at 18:47