【发布时间】:2015-01-09 16:06:52
【问题描述】:
我有一些类似于以下的实体(伪代码)
class A {
Integer aId;
}
class B {
Integer bId;
@ManyToOne
A a;
}
class C {
Integer cId;
@ManyToOne
A a;
}
我想使用 QueryDSL 根据 C 中的条件获取 B 的列表。我不想在 A 中创建一组 B 或一组 C。
如果我这样做
query.from(b, c).innerJoin(b.a, a).fetch().innerJoin(c.a, a).
where(c.cId.eq(1)).list(b);
然后,正如预期的那样,我得到了一个交叉连接。
如果我这样做
query.from(b).innerJoin(b.a, a).fetch().innerJoin(c.a, a).
where(c.cId.eq(1)).list(b);
然后,正如预期的那样,我收到“未声明的路径”错误。
我可以的
query.from(b, c).innerJoin(b.a, a).fetch().innerJoin(c.a, a).
where(c.cId.eq(1)).where(c.a.aId.eq(a.aId).list(b);
这会保留交叉连接,但会根据 where 子句限制结果。我想知道是否有办法在没有交叉连接的情况下做到这一点。
【问题讨论】:
标签: querydsl