438 words

LEFT (OUTER) JOIN problem when mappedBy is defined

2011-07-01 07:48

Hi all,

I want to get objects with their lists, even when the lists are empty. So I've witten this query:

"SELECT i FROM Invoice i LEFT OUTER JOIN i.itemList items"

But this query never returns invoices without items! Only invoices with items.

When I remove mappedBy from @OneToMany annotation, LEFT JOIN works correctly.

Is this normal behaviour?

Thank you



Sample application

public class JavaApplication {
    public static void main(String[] args) {
        EntityManagerFactory emf =
        EntityManager em = emf.createEntityManager();
        Invoice i1 = new Invoice("1");
        Invoice i2 = new Invoice("2");
        i2.getItemList().add(new InvoiceItem(i2));
        Invoice i3 = new Invoice("3");
        Query query = em.createQuery(
            "SELECT i FROM Invoice i LEFT OUTER JOIN i.itemList items");
        List resultList = query.getResultList();
public class Invoice {
    @OneToMany(mappedBy = "invoice", fetch= FetchType.EAGER, orphanRemoval=true, cascade= CascadeType.ALL)
    private List<InvoiceItem> itemList = new ArrayList<InvoiceItem>();
    private String name;
    public Invoice(String name){
        this.name = name;
    public List<InvoiceItem> getItemList() {
        return itemList;
    public String toString() {
        return name;
public class InvoiceItem{
    private Invoice invoice;
    InvoiceItem(Invoice i) {
        this.invoice = i;
anaq's picture
Joined on 2011-06-08
User Post #15
2011-07-01 08:54

I've forgotten the version - I've tested with 2.2.7 build 5 and 2.2.7 build 8

anaq's picture
Joined on 2011-06-08
User Post #16
2011-07-01 14:40

It was an ObjectDB bug. Please try build 2.2.7_09.

Thank you for this report.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #398

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.
Maximum file size: 32 MB