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
Michael
Sample application
public class JavaApplication { public static void main(String[] args) { com.objectdb.Enhancer.enhance("javaapplication.*"); EntityManagerFactory emf = Persistence.createEntityManagerFactory("$objectdb/db/test.odb"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Invoice i1 = new Invoice("1"); em.persist(i1); Invoice i2 = new Invoice("2"); i2.getItemList().add(new InvoiceItem(i2)); em.persist(i2); Invoice i3 = new Invoice("3"); em.persist(i3); em.getTransaction().commit(); Query query = em.createQuery( "SELECT i FROM Invoice i LEFT OUTER JOIN i.itemList items"); List resultList = query.getResultList(); System.out.println(resultList); em.close(); emf.close(); } } @Entity 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; } @Override public String toString() { return name; } } @Entity public class InvoiceItem{ @ManyToOne private Invoice invoice; InvoiceItem(Invoice i) { this.invoice = i; } }