openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <>
Subject Re: Limitations of eager fetching?
Date Mon, 27 Aug 2007 20:22:14 GMT
I do not think that you should be running into the limitation, given
your description. At least, the reason that the limitation is there
should not have any theoretical impact on that model.

The conceptual limitation is that every time we eagerly load a to-many
relation (true eager, not a parallel select), we significantly
increase the number of rows returned by the query. Of course, in
particular cases, this might not be an issue for sufficiently
low-cardinality relations. However, based on the fact that it's
typically not desirable to do multiple to-many joins, OpenJPA makes
the assumption that it's never beneficial. The upshot is that the
logic to handle weeding out duplicate records from a result set that
has an eager to-many only works for a single to-many relation.

So, the case that would not work would be if your Order class had a
to-many to LineItem and also a to-many to Approval, and you wanted to
eagerly fetch both relations.


On 8/23/07, Kevin Sutter <> wrote:
> Hi Guys,
> Can someone help me interpret a limitation specified in section 7.2:
>    - Once OpenJPA eager-joins into a class, it cannot issue any further
>    eager to-many joins or parallel selects from that class in the same query.
>    To-one joins, however, can recurse to any level.
> So, if I have the following code, am I hitting this limitation?
> public abstract class AbstractCustomer implements Serializable {
>     ...
>     @OneToOne(fetch = FetchType.EAGER)
>     @JoinColumns({@JoinColumn(name="OPEN_ORDER", referencedColumnName =
> "ORDER_ID")})
>     protected Order openOrder;
> public class Order implements Serializable {
>     ...
>     @OneToMany(fetch=FetchType.LAZY)
>     @ElementJoinColumn(name="ORDER_ID",referencedColumnName="ORDER_ID")
>     protected Set<LineItem> lineitems;
> In order to load all LineItems Eagerly, I have to start from Order (vs
> starting from Customer).
> If I do an em.find() on Customer.  Even if I specify Eager from Order to
> LineItems, it will not load the LineItems Eagerly.  Only if I do an
> em.findon the Order will I get the Join because LineItems is a
> collection.
> Have I interpretted the limitation correctly?  And, if so, can somebody
> provide some background on this limitation and what it would take to remove
> it?  I'm still not 100% comfortable with this area of the code...  :-)
> Thanks!
> Kevin

Patrick Linskey
202 669 5907

View raw message