Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use fetchType.LAZY and EAGER correctly?

diego10Aug 23 2013 — edited Aug 24 2013

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?

thanks!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2013
Added on Aug 23 2013
3 comments
1,134 views