Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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 LAZY load a OneToMany list

843833Jan 14 2008 — edited Apr 3 2008
Hi;
[Glassfish 9.1 Toplink]
In a simple parent child ejb3 entity bean, where then child list (@OneToMany in the parent entity) is annotated with a fetchtype LAZY;
How do I 'manually' load the child list on demand? I thought that by merely calling the getter on the child list, jpa will load it,
but I get back a list with null entries. With the exact same code, but with the fetchtype EAGER I correctly get the child list.

To be a little clearer: I am [remotely] calling a stateless session bean that does a em.find on the parent entity.
Of course in the remote client, detached, if LAZY fetched, I properly get a Toplink exception if I try to get the child list. Great.
BUT, the problem is that even in the server tier, in the same method in the session bean, before it returns the entity to the client,
I sometimes want to populate the parent entity with the child list (as if it was eager),
so I do a manual get on the child list, but it is an empty (non-instantiated) list, as observed by the debugger at the server tier.

Thank you much;
nat
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2008
Added on Jan 14 2008
4 comments
1,031 views