假设我们有一个类 Person
其中包含 Set<Book> books
.
要查找所有拥有《Effective Java》一书的人,您可以这样写:
select p from Person p left outer join fetch p.books as b where b.name='Effective Java'
现在,我怎样才能扭转这个查询,并找到所有 Person
没有这本书?
select p from Person p "where p.books does not contain book b where b.name='Effective Java'"
最佳答案
您可以利用NOT EXISTS
关键字:
select p
from Person p
where not exists (
select b from p.books b where b.name = 'Effective Java'
)
关于java - JPA 查询 "Set does NOT contain a certain item",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54480168/