Eclipselink扩展了JOIN子句 [英] Eclipselink extend JOIN clause
问题描述
当前代码:
CriteriaQuery criteriaQuery = cb.createQuery(MinutisPreke.class);
Root<MinutisPreke> from = criteriaQuery.from(MinutisPreke.class);
Join<LankomumasDiena, MinutisPreke> ld = from.join("lankomumasDiena", JoinType.LEFT);
cb.and(cb.equal(ld.get("intervalas"), 7));
生成以下查询:
SELECT COUNT(t0.pr_id) FROM preke AS t0
LEFT OUTER JOIN lankomumas AS t1
ON (t1.pr_id = t0.pr_id)
WHERE (t1.intervalas = 7)
如何在LEFT OUTER JOIN中添加语句使用条件查询的 ON 子句,以便我的代码生成此查询:
How to add statement in the LEFT OUTER JOIN ON clause using criteria query so my code would generate this query:
SELECT COUNT(t0.pr_id) FROM preke AS t0
LEFT OUTER JOIN lankomumas AS t1
ON (t1.pr_id = t0.pr_id) AND (t1.intervalas = 7)
编辑1:
如果你没看到第一和第二个查询的任何差异,请阅读此主题:
SQL join:where子句与on子句
推荐答案
EclipseLink a如本文所述,在2.5夜间构建中支持ON子句:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=367452
但它不是JPA规范的一部分,因此您需要将Join转换为EclipseLink的org.eclipse .persistence.internal.jpa.querydef.JoinImpl
EclipseLink added support for the ON clause in a 2.5 nightly build as described here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367452 but it is not a part of the JPA specification so you will need to cast the Join to EclipseLink's org.eclipse.persistence.internal.jpa.querydef.JoinImpl
((JoinImpl)ld).on(cb.and(cb.equal(ld.get("intervalas"), 7));
这篇关于Eclipselink扩展了JOIN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!