Eclipselink扩展了JOIN子句

时间:2013-01-14 09:04:42

标签: java jpa eclipselink criteria-api

当前代码:

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 join: where clause vs. on clause

1 个答案:

答案 0 :(得分: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));