This content has been marked as final.
Show 2 replies
-
1. Re: Properly using a OneToMany relationship using EJB 3.0
itsme Jun 18, 2007 3:10 AM (in response to thepriz)Hi,
you two different options:
First one is to changed the loading strategy of your relationship by adding the appropriate attributes to the annotation i.e.@OneToMany(fetch = FetchType.EAGER)
.
This is a standard declaration defined by the spec.
Second one is a little bit tricky because of the knowledge of cursor going to be closed. A lazy fetched relationship can be fully loaded by iterating over the collection using an iterator of an attached entity. Thus it is enough to call the relationships iterator method and the assoziated entities must be loaded.
Regards -
2. Re: Properly using a OneToMany relationship using EJB 3.0
mazz Jun 18, 2007 8:35 AM (in response to thepriz)Problem with that second solution is that it leads to the N+1 problem.
There is a third solution - use LEFT JOIN FETCH.
If you have a collection that is configure for lazy loading, you can execute a JPQL query that left join fetches the collection you want to eagerly load. There is plenty of info on the net about left join fetches if you want to learn more.
All of these solutions mentioned in this thread are not hibernate specific.