JP QL - Filtering result in a One To Many relationship

一个人想着一个人 提交于 2019-12-13 00:33:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!