Home » Support » Forum » LEFT (OUTER) JOIN problem when mappedBy is defined

LEFT (OUTER) JOIN problem when mappedBy is defined


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;

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


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)

Post Reply

To post a reply and/or subscribe to update notifications - please login