openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paulo Rodrigues Pinto <regularj...@gmail.com>
Subject How to eagerly fetch two-level nested associations?
Date Sun, 02 Dec 2012 01:04:06 GMT
I'm trying to efficiently fetch a two-level nested association using
OpenJPA 2.2.0. Basically, I have one Athat has one B that has many C:

@Entitypublic class A {
    ...

    @ManyToOne(fetch=FetchType.EAGER)
    private B b;}
@Entitypublic class B {
    ...

    @OneToMany(mappedBy="b", fetch=FetchType.EAGER)
    private List<C> cs;}
@Entitypublic class C {
    ...}

My JPQL query is as follows:

SELECT a
FROM A a
WHERE a.id = some condition

 I set the EagerFetchMode<http://openjpa.apache.org/builds/2.2.0/apache-openjpa/docs/ref_guide_perfpack_eager.html>
to
"PARALLEL" in order to have a second query that retrieves the Cs of all the
Bs:

<property name="openjpa.jdbc.EagerFetchMode"
value="parallel"/><property
name="org.apache.openjpa.persistence.jdbc.EagerFetchMode"
value="PARALLEL"/>

 The problem is that openjpa is generating n+1 queries instead of 2: one
for the As and Bs and one for each C:

SELECT *FROM aLEFT OUTER JOIN b
    ON a.b_id = b.id WHERE some condition

 and n times

SELECT *FROM c WHERE c.b_id = x

 *How can I make openjpa issue two queries instead of n+1?*

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