3 Replies Latest reply: Aug 24, 2013 9:14 AM by dvohra21 RSS

    How to use fetchType.LAZY and EAGER correctly?


      HI all,

      I understand the basics of these two, I have two entities with 1-n relationship, in my first entity I have


          @OneToMany(cascade = CascadeType.ALL,mappedBy = "trGuia",fetch = FetchType.LAZY)

          private List<TRItem> itemsList;


      but I get {IndirectList: not instantiated} when I call for the entity1.getItemsList();

      if I chage to

      @OneToMany(cascade = CascadeType.ALL,mappedBy = "trGuia",fetch = FetchType.EAGER)

          private List<TRItem> itemsList;

      It works but eager loads everything even if the client doesn't need it, how should I use lazy so I get better performance and the list Items

      I am looking for? or I must eager?