JPQL 基于条件的多对多连接

JPQL ManyToMany Join based on codition

我需要有关 JPQL 查询的帮助。

我有实体 Author 和实体 Book,它们在 JPA 中作为 ManyToMany 关系相关,其中作者拥有拥有方。 我需要的是一个查询来获取所有不是某个作者写的书。

我已经尝试过查询,但它不起作用。

Select b From Book b Where (Select a From Author a where a.AuthorId = :authorId) Not Member of b.authors) Or b.authors Is Empty);

我缺少什么才能让查询正常工作?预先感谢您的帮助。

尝试其中之一,它应该确实有效,但当您分享您遇到的错误时它会更有帮助。

SELECT b FROM Book b JOIN b.authors authors WHERE (:authorId NOT IN authors) OR (:authorId Is Null);

SELECT b FROM Book b JOIN b.authors authors WHERE (:authorId NOT IN b.authors) OR (:authorId Is Null);

希望对您有所帮助。