JQL 多对多 select where :item not in items
JQL Many to Many select where :item not in items
当我们有这个结构时:
@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 中的所有行的情况下做到这一点。
有一个更好的方法,使用 member of
运算符:
select a from A a where :bInstance not member of a.b
当我们有这个结构时:
@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>
.
我正在尝试这个解决方案:
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 中的所有行的情况下做到这一点。
有一个更好的方法,使用 member of
运算符:
select a from A a where :bInstance not member of a.b