3

我一直在尝试构建一个 JPQL 查询,并希望比我有更多 JPA 经验的人能提供帮助。考虑以下两个实体:

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

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

如果我想返回一个特定的作者(按名称)并急切地获取(即 LEFT JOIN FETCH)Book.inPrint 标志为真的书籍,我将如何在 JPQL 中表达它?

4

1 回答 1

2
SELECT a FROM Author a LEFT JOIN a.books b WHERE b.inPrint = true OR b is null
于 2010-08-19T15:32:47.070 回答