How do I achieve a Deep Fetch using JOIN FETCH?

#1

I have an Entity type which is contains a collection of Embeddable objects, which in turn themselves contain a collection of Embeddable objects:

@Embeddable
class A {
    String val;
};

@Embeddable
class B {
    List<A> aList;
};

@Entity
class C {
    @Id long id;
    List<B> bList;
};

 

Usually I'm content to have the B's and A's be lazily loaded, but I have a circumstance where I need to be able to work with the whole C object, with all its parts, as a detached object.

I know that I can express one level of eager fetch in JPQL as follows:

SELECT c FROM C JOIN FETCH c.bList WHERE c.id=:id

But when I attempt to take it to the 2nd level:

SELECT c FROM C JOIN FETCH c.bList JOIN FETCH c.bList.aList WHERE c.id=:id

I get an error along the lines of:

Invalid fetch path: bList.aList for type C (#element is expected)

Admittedly, this makes sense, because '.' can only be applied to collections.  So I tried:

SELECT c FROM C JOIN c.bList b JOIN FETCH c.bList JOIN FETCH b.aList WHERE c.id=:id

but that gets the same error.

I should pause to mention that I am aware of the problem in this thread, but my situation goes beyond that.

So does anyone know how to get this deep fetch to work?  I assume I will need to use version 2.4.1_06 or newer, per the case referenced in the above thread.  But is there a syntax I can use for my query to get the result I'm looking for?

 

Thanks,

Ben Schreiber

Fast Model Technologies

#2

Please try build 2.4.7_11 that should add this ability.

Actually, it seems that one JOIN FETCH should be sufficient in this case:

SELECT c FROM C c JOIN FETCH c.bList.aList WHERE c.id=:id
ObjectDB Support

Reply