【问题标题】:QueryDSL join on multiple entities with one way relationshipsQueryDSL 以单向关系连接多个实体
【发布时间】: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


    【解决方案1】:

    在不更改实体类型的情况下,您将需要使用交叉连接来连接查询中的实体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 2015-04-27
      • 2015-10-24
      • 2013-01-20
      • 2023-03-31
      相关资源
      最近更新 更多