ObjectDB ObjectDB

LEFT JOIN FETCH over empty embedded collection returns no results

#1

First of all, thank you for promptly implementing JOIN FETCH over nested paths in response to my inquiry a few months ago.

However, I have run into one problem: if an embedded collection is empty, but I attempt to LEFT JOIN FETCH all the members of a collection within a (non-existent) member of the first collection, the result of the overall query is an empty set.

To use the example from my original post:


@Embeddable
class A {
    String val;
};

 


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

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

If I have an instance of C where bList is empty, the following works (returns my instance of C):

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

But if I include the full nested fetch, it fails, returning an empty result list:

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

The semantics implied by LEFT JOIN suggest that in the case of this instance of C, the two should both return the same value.

I've checked my server, and there are no errors logged for this.

edit
delete
#2

The problem may be with the expression c.bList.val. Path expressions are considered as INNER JOIN by JPA, although apparently it makes sense to consider path expressions in LEFT JOIN FETCH differently.

ObjectDB Support
edit
delete
#3

So can I expect this to be addressed in an upcoming release, or should I just avoid creating empty collections when I expect to JOIN FETCH through them?

edit
delete
#4

The query in your initial post is invalid:

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

since B instances do not include a val field (there is also an invalid ; symbol at the end of the query).

 

The following query returned results:

SELECT c FROM C c LEFT JOIN FETCH c.bList.aList

but this query didn't:

SELECT c FROM C c LEFT JOIN FETCH c.bList.aList.val

It seems that the LEFT JOIN FETCH affected only the last component in the path. Please try build 2.5.0_06 that should change this behavior.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.