4

当前代码:

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子句中添加语句,以便我的代码生成此查询:

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 连接:where 子句与 on 子句

4

1 回答 1

2

EclipseLink 在 2.5 nightly build 中添加了对 ON 子句的支持,如下所述: https ://bugs.eclipse.org/bugs/show_bug.cgi?id=367452 但它不是 JPA 规范的一部分,因此您需要将 Join 转换为 EclipseLink 的 org.eclipse.persistence.internal.jpa.querydef.JoinImpl

((JoinImpl)ld).on(cb.and(cb.equal(ld.get("intervalas"), 7));
于 2013-01-14T13:01:57.640 回答