问题
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:
SELECT a FROM Author a LEFT JOIN a.books b WHERE b.inPrint = true OR b is null
来源:https://stackoverflow.com/questions/3522572/jp-ql-filtering-result-in-a-one-to-many-relationship