tags:

views:

27

answers:

1

I am stuck trying to construct a JPQL query and was hoping someone with more JPA experience than mine could help. Consider the following two entities:

class Author{
  String name
  @OneToMany(mappedBy="author")
  Set<Book> books
}

class Book{
  String title  
  Boolean inPrint
  @ManyToOne
  Author author
}

If I want to return a specific Author (by name) and eagerly fetch (ie LEFT JOIN FETCH) the books where the Book.inPrint flag is true, how would I express that in JPQL?

+1  A: 
SELECT a FROM Author a LEFT JOIN a.books b WHERE b.inPrint = true OR b is null
grigory