Eclipselink extend JOIN clause

╄→尐↘猪︶ㄣ 提交于 2019-12-19 08:27:09

问题


The current code:

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));

generates the following query:

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)

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)

EDIT 1: If you don't see any difference in first and second querys, please read this thread: SQL join: where clause vs. on clause


回答1:


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));


来源:https://stackoverflow.com/questions/14315547/eclipselink-extend-join-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!