FROM 在 QueryDSL 上丢失

FROM missing on QueryDSL

我正在使用 QueryDSL v4.1.4 来执行此查询

.select(/*many fields*/)
.from(_product)
.join(_event).on(_product.event.eq(_event))
.join(_customer).on(_event.customer.eq(_customer))
.leftJoin(_person).on(_customer.person.eq(_person))
.leftJoin(_organization).on(_customer.organization.eq(_organization))
.where(/*many filters*/)

我的代码生成这个 SQL

SELECT --many fields
FROM product t3 
LEFT OUTER JOIN person t1 ON (t0.p_id = t1.p_id) 
LEFT OUTER JOIN organization t2 ON (t0.o_id = t2.o_id), 
event t4, 
customer t0
WHERE --many filters

但我预计会生成此 SQL(此 SQL 在我的 DBMS 中工作正常)

SELECT --many fields
FROM product t3,
event t4, 
customer t0
LEFT OUTER JOIN person t1 ON (t0.p_id = t1.p_id) 
LEFT OUTER JOIN organization t2 ON (t0.o_id = t2.o_id)
WHERE --many filters

尝试执行查询时出现此异常

missing FROM-clause entry for table "t0" (customer)

修复它的失败想法

是否有任何方法可以强制对查询应用联接的顺序?

为什么 t3t4 上没有连接?我原以为这会导致这些表的笛卡尔积。也许连接在 WHERE 子句中,示例中没有显示?如果是这样,为什么要混合 ANSI SQL 和非 ANSI SQL,而不是在 FROM 子句中执行所有连接?我不认为这是一个 querydsl 问题,而是 SQL 的问题,你最好先解决它。

要生成您问题中要求的 SQL,这应该可以解决问题。但是,您应该重构您的查询以在 FROM 子句中执行 ANSI 样式连接,并且 querydsl 将 "just work".

.select(/*many fields*/)
.from(_product)
.from(_event)
.from(_customer)
.leftJoin(_person).on(_customer.person.eq(_person))
.leftJoin(_organization).on(_customer.organization.eq(_organization))
.where(/*many filters*/)

编辑

在评论中,Esvin指出有一个varargs version of the from method, so the three calls to the standard versionfrom方法可以简化为一个:.from(_product, _event, _customer)