openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: Eager fetch leads to out of bounds error
Date Sat, 07 Nov 2009 21:59:00 GMT
On Thu, Nov 5, 2009 at 1:27 PM, Daryl Stultz <> wrote:

> On Thu, Nov 5, 2009 at 1:48 PM, Michael Dick <
> >wrote:
> > On Thu, Nov 5, 2009 at 12:17 PM, Daryl Stultz <>
> wrote:
> >
> >
> > I think I misunderstood your point (I thought the FETCH was implied).
> >
> I think I asked a new question, not necessarily based on your previous
> input, so I don't think you misunderstood anything, I just changed the line
> of questioning on you. :-)
> >
> > Adding in the fetch clause:
> >
> > A JOIN FETCH differs from a JOIN in two ways :
> >  * You will get one reference to the entity on the left side of the JOIN
> > for every related entity on the right side of the JOIN.
> >
> This I misunderstood long ago before our discussion - I didn't
> misunderstand
> what you were saying about it. I don't think. Anyway.
> >  * The relationship on the right side of the JOIN will be eagerly loaded.
> >
> This is what I'm having trouble with. If a JOIN would return the children,
> isn't it implied that they are eagerly loaded? What exactly does eagerly
> loaded mean in this case? Picture this:
> select a, bCol.b from A as a
> join a.bCol as bCol
> compared to this:
> select a from A as a
> join fetch a.bCol
> They both return all the child B entities (same number of "rows") but the
> second puts the B's into the appropriate a.bCol collection. In both cases,
> B's are being loaded. Is it the bCol collection you are referring to as
> being eagerly loaded? Sorry if I'm putting too fine a point on this, just
> trying to cement it all in my brain.
In the join fetch case the eager loading is a side effect of the query, the
entities on the right hand side are not part of the query results.

Another difference is that with a join fetch you can't set an identification
variable for the entities on the right hand side.
For example :
"select a from A join fetch a.bCol b" would throw an exception.

Having multiple references to the same entity from the left side of the
query is a side effect of this loading as far as I can tell.

I can't claim to be an expert here, I'm learning as I go. A lot of how we
handle joins seems a bit odd to me. Sorry if this isn't terribly
enlightening. The best reference I can give you is section 4.4.5 of the JPA
1.0 specification. Mike Keith's Pro EJB3 book is also a good place to look.


> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message