341 words

LEFT JOIN FETCH over empty embedded collection returns no results

#1
2013-05-23 11:06

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.

FastModel
FastModel's picture
Joined on 2011-02-07
User Post #32
#2
2013-05-23 11:08

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,551
#3
2013-05-23 16:01

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?

FastModel
FastModel's picture
Joined on 2011-02-07
User Post #33
#4
2013-05-24 15:53

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,555

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel