【发布时间】:2015-03-29 14:04:10
【问题描述】:
当我们有这个结构时:
@Entity
public class A {
....
@ManyToMany(mappedBy = "a")
public Set<B> getB() {
return b;
}
和
@Entity
public class B {
...
@ManyToMany
public Set<A> getA() {
return a;
}
我们如何查询实体 A 以获取给定 b 值不在Set<B> 中的行?我的意思是,获取所有在Set<B> 中没有给出 b 的 A。
我正在尝试这个解决方案:
from A where :bInstance not in b
和
select a from A a where a not in (b.a from B b where b.name = :name)
和
select a from A a where a not exists (b.a from B b where b.name = :name)
但没有运气。
我知道我可以通过查询所有 A 然后对其进行迭代和过滤来做到这一点,但我想在不查询 db 中的所有行的情况下做到这一点。
【问题讨论】:
标签: hibernate jakarta-ee jpa